![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
whats upppp!!!im new to java, actually i just started to learn it....i just need to know if it is allowed to use if-else statement within the while statement...and i need to know if i can use Boolean operators within while statement's condition?????THANX!!![color=blue]
|
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 4
![]() |
Yes, and yes. Though wouldn't it be faster to test your assumptions with a simple program to see if they work?
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
Of course... those are permitted in any language... as well as a while loop, with nested loops 10 deep, inside of a while loop that is inside of a while loop, with condition checking throughout.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
this is a very useful technique called a "sentinel-controlled loop"
psuedo: boolean sentVal = false while(sentVal != true) { do some things; some of the things (like a user choice) may want you to quit the loop; so whenever that (IF) situation comes up; sentVal = true; //BAM! out of the loop } the above "user quitting" scenario is a good example and works great with a do-while loop so the program runs once and then asks if they want to do it again. :ph34r:
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|