Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

if's

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why somehow during my 4th If statement that my Boolean 'up' gets changed to False. I don't understand if 'up' is now changed to False that 'i' does not decrement. I figure that if the If does not satisfy the condition it should simply be skipped. But that does not seem to be the case.


CONSOLE RESULTS:
Value of i = 0
Value of up-1 = true
Value of up-2 = true
Value of up-3 = true
TRUE CONDITION
Value of up-4 = true
Value of up-5 = false
Value of i = 1
Value of up-1 = false
Value of up-2 = false
Value of up-3 = false
TRUE CONDITION
Value of up-4 = true
Value of up-5 = false
Value of i = 2
Value of up-1 = false
Value of up-2 = false
Value of up-3 = false
TRUE CONDITION
Value of up-4 = true
Value of up-5 = false
Value of i = 3
...etcetera....

Thanks

 
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is something that is tricky for those new to Java


This assigns true to up and checks if up is true. Which it always is.


This checks if up is true.

You want the second one.
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Grrrr! I knew that but noobed it nonetheless.
Thanks!
 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George,
What do you mean by 'noobed'?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's one reason why I think it's preferable to use if(up) and if(!up), instead of if(up == true) and if(up == false).
 
Marshal
Posts: 78427
374
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never try writing == false or == true.
Always write if (up)... or if (!up)...
That should prevent that particular error.
 
Jeanne Boyarsky
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Ngom wrote:Hi George,
What do you mean by 'noobed'?


noob is slang for someone new to something. It is a synonym for newbie.

Noobed is not something I had heard before, but I can infer it to mean to make a mistake that a new person would make.
 
Ranch Hand
Posts: 116
2
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Never try writing == false or == true.
Always write if (up)... or if (!up)...
That should prevent that particular error.



This is something I need to keep in mind for myself also. I tend to write == true or == false.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


noob is slang for someone new to something. It is a synonym for newbie.

Noobed is not something I had heard before, but I can infer it to mean to make a mistake that a new person would make.


Thank you Jeanne. I now get the meaning.
 
Campbell Ritchie
Marshal
Posts: 78427
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which case it would be best to avoid noob as a verb in future, please. One reason for requiring real words is that they cause confusion to non‑native English speakers.
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the rules mistake.
And, thank you all for the further discussion and advice.
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic