DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Loops (http://www.daniweb.com/forums/thread15189.html)

WillisTi Dec 7th, 2004 9:03 am
Loops
 
Hi,

Fairly new to java and programming. Could anyone explain the difference between a for loop and a do while loop in relation to writing a program and typing in numbers and displaying the total.

Thanks

jwenting Dec 7th, 2004 9:27 am
Re: Loops
 
A for-loop is typically used when the number of passes through the loop is known in advance.
A while loop is typically used when the number of passes is NOT known in advance.
A do-while loop is rarely used but can be useful if the loop is known to have to run at least once and the total number of runs isn't known (or at least not known before the end of that first run).

starsunited Dec 9th, 2004 4:29 am
Re: Loops
 
Quote:

Originally Posted by jwenting
A for-loop is typically used when the number of passes through the loop is known in advance.
A while loop is typically used when the number of passes is NOT known in advance.
A do-while loop is rarely used but can be useful if the loop is known to have to run at least once and the total number of runs isn't known (or at least not known before the end of that first run).


yea just want to add on. which loop you use depends on what you want to do. As for while and do while loop , the concept is almost the same, it depends on ur preference.

bommavj Oct 23rd, 2006 2:29 pm
Re: Loops
 
Quote:

Originally Posted by WillisTi (Post 73549)
Hi,

Fairly new to java and programming. Could anyone explain the difference between a for loop and a do while loop in relation to writing a program and typing in numbers and displaying the total.

Thanks


for loop is evaluate up to the condition is false.

whereas

do-while loop is evaluate once eventhough the condition is false.


All times are GMT -4. The time now is 10:34 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC