Loops

Reply

Join Date: Dec 2004
Posts: 1
Reputation: WillisTi is an unknown quantity at this point 
Solved Threads: 0
WillisTi WillisTi is offline Offline
Newbie Poster

Loops

 
0
  #1
Dec 7th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Loops

 
0
  #2
Dec 7th, 2004
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).
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 44
Reputation: starsunited is an unknown quantity at this point 
Solved Threads: 1
starsunited's Avatar
starsunited starsunited is offline Offline
Light Poster

Re: Loops

 
0
  #3
Dec 9th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: bommavj is an unknown quantity at this point 
Solved Threads: 0
bommavj bommavj is offline Offline
Newbie Poster

Re: Loops

 
0
  #4
Oct 23rd, 2006
Originally Posted by WillisTi View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC