943,513 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2852
  • Java RSS
Dec 7th, 2004
0

Loops

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WillisTi is offline Offline
1 posts
since Dec 2004
Dec 7th, 2004
0

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 9th, 2004
0

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.
Reputation Points: 11
Solved Threads: 1
Light Poster
starsunited is offline Offline
44 posts
since Dec 2004
Oct 23rd, 2006
0

Re: Loops

Click to Expand / Collapse  Quote originally posted by WillisTi ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bommavj is offline Offline
3 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: loops
Next Thread in Java Forum Timeline: jdk1.5.0_09 and enums





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC