What is a Java do Loop?

A Java do loop is similar to the Java while loop, except that the while test happens at the bottom of the loop. This means that the loop always executes at least once.

Java do loop syntax

The syntax of a do loop in Java is:


do {
statement(s)
} while (expression);

Example Java do loop

Here is a Java do loop that prints the number 1 -- even though the test fails.


int loopvar = 1; // Declare and initialize the loop counter
do {
System.out.println(loopvar); // Print the variable
loopvar = loopvar + 1; // Increment the loop counter
} while (loopvar >= 10); // Test and loop




Top 5 Free Networking Tools

Bookmark What is a Java do Loop?

Latest Blog Posts


English English GermanGerman SpanishSpanish FrenchFrench ItalianItalian PortuguesePortuguese RussianRussian DutchDutch
GreekGreek HindiHindi JapaneseJapanese KoreanKorean ChineseChinese Chinese (Simplified)Chinese (Simplified) ArabicArabic

Copyright 2009 Tech-FAQ. All rights reserved. Privacy Policy.