| | |
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).
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).
•
•
•
•
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.
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- Need Advice on for loops with vowels (Java)
- Loops (C++)
- Need some help with my do-while and while loops (Java)
- Help with loops (Java)
- Program Help Using For Nested Loops (C++)
- merged:nesting loops (C++)
- help for program involving switch loops and file (C++)
Other Threads in the Java Forum
- Previous Thread: loops
- Next Thread: jdk1.5.0_09 and enums
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






