Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Can I Do It?? (http://www.programmingforums.org/showthread.php?t=1191)

thenewkid Nov 18th, 2004 9:28 AM

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]

Eggbert Nov 18th, 2004 10:41 AM

Yes, and yes. Though wouldn't it be faster to test your assumptions with a simple program to see if they work?

Infinite Recursion Nov 18th, 2004 7:39 PM

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.

bl00dninja Nov 19th, 2004 1:34 AM

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