![]() |
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]
|
Yes, and yes. Though wouldn't it be faster to test your assumptions with a simple program to see if they work?
|
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.
|
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: |
| All times are GMT -5. The time now is 1:20 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC