• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

if and while statements and meanings.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.




One possible place to start the learning, is with the Oracle Java tutorials....

http://docs.oracle.com/javase/tutorial/

Henry
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java can most definitely be used to learn software programming.

In your case, I would strongly advise learning the basic concepts first.

If you really do not understand what "if" means, or what the greater than or less than signs mean,
then you have to start at the very beginning.

http://www.dummies.com/store/product/Beginning-Programming-For-Dummies-4th-Edition.productCd-0470088702.html

WP
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



believe it or not, an if statement in java is just like and English if-statement. for example, if i said:



that's pretty obvious what to do, right? Java works the same way



so this says "If the nightLight.isOn variable is equal to true, call the nightLight.turnOff() method. Else, call the nightLight.turnOn() method".
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William P O'Sullivan wrote:

http://www.dummies.com/store/product/Beginning-Programming-For-Dummies-4th-Edition.productCd-0470088702.html

WP



@Wilson: I don't know how good that particular Dummies book is, but I wouldn't expect it to give you any more than the very basic fundamentals of programming in general (and maybe it has some Java-specific examples, I don't know). If you just want to learn what those things mean in Java, then Oracle's Java tutorial is fine.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

H Biz wrote:

if chocolateBarPrice < pocketChange
then: buy
else: null - i think thats correct


not sure what you mean by "else: null". Java does not require you to have an else, so you could just do this:



H Biz wrote:
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


"else" statements don't work with "while" statements. so this should really be more like


 
reply
    Bookmark Topic Watch Topic
  • New Topic