Java While Loop
Java Tutorial » Java While Loop
Loops are used to execute a block of code as long as a particular condition is reached (specified condition is true). This Java code make code more readable, save time and reduce errors.
Example:
Output:
11
12
13
14
15
public class Main {
public static void main(String[] args) {
int i = 11;
while (i < 16) {
System.out.println(i);
i++;
}
}
}
public static void main(String[] args) {
int i = 11;
while (i < 16) {
System.out.println(i);
i++;
}
}
}
Output:
11
12
13
14
15
In while loop, condition is evaluated first and if it returns true the statements inside while loop execute, else if condition returns false, the control comes out of loop and jumps to the next statement after while loop.
Do .. While Loop, example
This loop (Do .. While Loop) will execute the code block inside once, before checking if the condition is true, then it will repeat the sequence as long as the condition will be true.
Syntax: Do / While Loop.
do {
// code block to be executed
}
while (condition);
// code block to be executed
}
while (condition);
The loop will always be executed at least once, even if the condition is false, because the loop will be executed before condition while.
Example: Do / While Loop.
12
13
14
int i = 12;
do {
System.out.println(i);
i++;
}
while (i < 14);
Output: do {
System.out.println(i);
i++;
}
while (i < 14);
12
13
int i = 14;
do {
System.out.println(i);
i++;
}
while (i < 14);
Output: do {
System.out.println(i);
i++;
}
while (i < 14);
14
Java While Loop, ejemplo, break, do,true, else, iterator, if, =, array
Java While Loop - java
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.