| | |
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
- Program Help Using For Nested Loops (C++)
- 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)
- 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 |
actuate add android api applet application applications array arrays automation balls bank binary bluetooth business chat class clear client code codesnippet collections component database defaultmethod development dice digit dragging ebook eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health hql html hyper ide idea image infinite int integer invokingapacheantprogrammatically j2me java javame javaprojects jni jpanel julia linux list main map method methods mobile myregfun mysql netbeans nonstatic openjavafx parameter pearl php problem program project recursion repositories scanner scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string sun superclass swing swt thread threads tree windows






