Home » Java Basics » while loop

while loop

Java do while example

There are four ways of looping with Java: for loops, for-each loops (since Java 1.5), while loops and the do-while loops. In this example, I will show how to use the do-while loops to repeat blocks of statements in Java.             do-while structure A do-while has the following base structure: do { // the code ...

Read More »

Simple while loop

With this example we are going to demonstrate how to use a simple while statement in Java. The while statement continually executes a block of statements while a particular condition is true. In short, to use a simple while loop you should: Create a while statement that evaluates an expression, which must return a boolean value and has a statement. ...

Read More »