🌐
W3Schools
w3schools.com › java › java_while_loop_do.asp
Java Do/While Loop
The do/while loop is different: it will always run the code block at least once, even if the condition is false from the start. In the example below, the variable i starts at 10, so i < 5 is false immediately.
🌐
BeginnersBook
beginnersbook.com › 2015 › 03 › do-while-loop-in-java-with-example
do-while loop in Java with example
Here we have an integer array and we are iterating the array and displaying each element using do-while loop.
Discussions

Java do..while loops explained with examples - Guide - The freeCodeCamp Forum
Do…While Loop The do while is similar to the while loop, but the group of statements is guranteed to run at least once before checking for a given condition. An important thing to note is ‘while’ loop is an exit control loop. while(it will not necessarily be executed), ‘do while’ ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
September 9, 2019
do while loop - Java Basic
Tanguy Muffat is having issues with: Hi guys, I would need you support. I'm stucked under challenge 2/3 where I'm being asked: "Now continually prompt the user in a do whil... More on teamtreehouse.com
🌐 teamtreehouse.com
2
November 20, 2017
Java Using do-while loop - Stack Overflow
You should use a do-while. A loop and and repeatable actions. That is not that difficult. You need to put the input of an Integer into the loop and check if it is the highest or lowest so far. The loop ends after 5 inputs and you can print the highest and the lowest. Ok - now try again. ... import java... More on stackoverflow.com
🌐 stackoverflow.com
Java: When to use a While Loop?
Imagine you have a collection of 1,000,000 songs. You want to search for one song specifically, and return that song (or, if the song doesn't exist in the collection, tell you it wasn't found). A for or for-each loop could accomplish that, but it's going to loop 1,000,000 times even if the song is the very first record checked, which is a huge waste of time and power. If you write a while loop and then have it stop when a matching record is found, it runs exactly as much as is necessary and no more. Another example -- imagine a simple text-based console app that reads input from a user and then prints it out on the screen, but then closes when they type "quit". If you put the steps of your program - asking the user for input, assigning it to a variable, and then printing it out - in a for/for-each loop, how do you know how many times to run it? A while loop that stops running when the user types "quit" lets the user flexibly quit whenever they want, whether on 0 entries or 200. There's a lot of other applications but hopefully these are useful to conceptualize at least. More on reddit.com
🌐 r/learnprogramming
19
13
March 29, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-do-while-loop-with-examples
Java Do While Loop - GeeksforGeeks
The loop continues until the condition c <= 5 becomes false, after which the loop terminates. ... Note: The test_expression in a do-while loop must evaluate to a boolean value; otherwise, a compile-time error occurs.
Published   1 month ago
🌐
Tutorialspoint
tutorialspoint.com › java › java_do_while_loop.htm
Java - do...while Loop
The following diagram shows the flow diagram (execution process) of a do while loop in Java - In this example, we're showing the use of a while loop to print numbers starting from 10 to 19.
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
The do...while loop is similar to while loop. However, the body of do...while loop is executed once before the test expression is checked. For example,
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
How Tos Add Two Numbers Swap Two ... Loop Loop Through an Enum ... assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String ...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › while.html
The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
Therefore, the statements within the do block are always executed at least once, as shown in the following DoWhileDemo program: class DoWhileDemo { public static void main(String[] args){ int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › loops-in-java
Java Loops - GeeksforGeeks
The do-while loop ensures that the code block executes at least once before checking the condition. Example: The below Java program demonstrates a do-while loop that prints numbers from 0 to 10 in a single line.
Published   August 10, 2025
Find elsewhere
🌐
SitePoint
sitepoint.com › blog › java › java’s while and do-while loops in five minutes
Java's While and Do-While Loops in Five Minutes — SitePoint
November 5, 2024 - The primary difference between a while loop and a do-while loop in Java lies in their execution. A while loop first checks the condition before executing the loop body. If the condition is false at the start, the loop body will not execute even once. On the other hand, a do-while loop executes the loop body first and then checks the condition.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-do-while-loop
Java do while loop | DigitalOcean
August 3, 2022 - Here is a simple java do-while loop example to print numbers from 5 to 10.
🌐
ScholarHat
scholarhat.com › home
do...while Loop in Java - Flowchart & Syntax (With Examples)
September 6, 2025 - The update expression in the do...while is the one that updates the variable of the loop. It may increment or decrement depending on the specifications. The update expression makes sure that at some point the test expression will evaluate to 'False' and the loop will terminate eventually. Consider this example below in Java Online Editor to identify both the expressions of the do...while loop.
🌐
DevQA
devqa.io › java-do-and-do-while-statements
Java While and Do-While Loops with Code Examples
In this example, the loop asks the user to enter a number repeatedly until they input 0. Even if the user inputs 0 on the first try, the loop’s code block will still execute once before checking the condition.
🌐
freeCodeCamp
forum.freecodecamp.org › guide
Java do..while loops explained with examples - Guide - The freeCodeCamp Forum
September 9, 2019 - An important thing to note is ... even if the conditon is not true). do { // Statements } while (condition); Example int iter_DoWhile = 20; do { System.out.print (iter_DoWhi......
Top answer
1 of 2
3
Hi Tanguy, I have seen this problem come up a lot. You do not actually need a boolean to run your do while loop, and you can simplify it a lot by having the loop depend on the response directly. java // I have initialized a java.io.Console for you. It is in a variable named console. String response; do{ response = console.readLine("Do you understand do while loops?"); }while(response.equalsIgnoreCase("no")); You may also include your print statement that you included using if(response.equalsIgnoreCase("no")). HOWEVER, with all that being said, what you did actually works fine! You just made a typo in your code. You wrote invalidReponse not invalidReSponse, as declared outside your loop. You can see these errors easily if you check the compiler error (You would see a symbol not found error point to that variable) Hope that helps!
2 of 2
0
I think i'm very unfamiliar with this kind of Java syntax. Using the console.printf() instead of System.out.println() and console.readLine() instead of scanner.nextLine(). I still don't understand why Tanguy Muffat's program works after fixing the syntax error. I don't understand how having the [while(response.equalsIgnoreCase("no"));] at the bottom works. Normally i would expect it to look more like : do{ while(response.equalsIgnoreCase("no")) { console.printf("Sorry you cannot continue the training. Train harder to understand the concept. \n"); }} I would think that a while condition with no brackets under it and nothing inside of it wouldn't work. In Tanguy Muffat's program it looks like the while loop is completely outside of the do loop.
🌐
Upgrad
upgrad.com › home › blog › software development › do while loop in java: syntax, examples, and practical applications
Do-While Loop in Java: Examples, Applications & Tips 2025
September 10, 2025 - The loop continues executing as long as i is less than or equal to the specified limit num. This example shows that do while syntax Java loops are well-suited for tasks requiring cumulative calculations that must run at least once.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-while-loop-with-examples
Java while Loop - GeeksforGeeks
Explanation: In the above example, the while loop runs until "i" is less than 6 and prints "Hello World" 5 times. Example: Calculating the Sum of Numbers from 1 to 10 with Java while Loop
Published   1 month ago
🌐
Stack Overflow
stackoverflow.com › questions › 71235205 › java-using-do-while-loop
Java Using do-while loop - Stack Overflow
That is not that difficult. You need to put the input of an Integer into the loop and check if it is the highest or lowest so far. The loop ends after 5 inputs and you can print the highest and the lowest.
🌐
DataCamp
datacamp.com › doc › java › java-while-loop
Java While Loop
This example demonstrates an infinite while loop, where the condition is always true. The break statement is used here to exit the loop, preventing it from running indefinitely. import java.util.Scanner; public class InputValidationExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number; System.out.println("Enter a number between 1 and 10:"); number = scanner.nextInt(); while (number < 1 || number > 10) { System.out.println("Invalid input.
🌐
IONOS
ionos.com › digital guide › websites › web development › java do-while loop
How to use the Java do-while loop - IONOS
January 3, 2025 - This condition is always expressed as a Boolean ex­pres­sion, meaning, within the program’s logic, it evaluates to either true or false. A common and useful example of such an ex­pres­sion is a counter variable, which allows you to determine ...
🌐
BeginnersBook
beginnersbook.com › 2015 › 03 › while-loop-in-java-with-examples
While loop in Java with examples
The initialization done with i=0 Then goto while loop and check the condition i<4(i=0) It is true goto the loop body execute the looping statement i.e., args[0] Then increment the i value by 1 After incrementing again check the while loop condition ……. …… Until the condition is false. It prints given o/p ….thats all ... i would like to print all the tables with while loop for example i want the output as : 1*1=1 1*2=2 ...