Wilson Oluwasegun wrote:Hello, I'm new to java and still don't understand the true functions of if and while statements and why the greater than sign(>) and less than signs(<) are introduced as well as this types : beerNum = beeNum - 1;
i'm so eager to understand java. Would really appreciate your help.
If statements are just like real life if statements.
If somethings is <insert outcome: true/false/higher/lower>
then do X
else do Y
So a real world example:
If day is a week day
then: go to work
else: stay at home
If phone rings
then: answer call
else: leave alone
> greater than
and
< less than
signs, are used to compare items - especially useful in if conditions.
if chocolate bar price is less than change in my pocket
then: buy
else; dont buy
if chocolateBarPrice < pocketChange
then: buy
else: null - i think thats correct
A while loop is used when something needs to continually happen until a condition is met to stop/break the loop.
For example:
While bank balance is greater than $50
buy beer
else: go home
becomes
While bankBalance > 50
buy beer
bank balance - 5
else: go home
Im a noob to so just read up on what I say - I may be wrong too