AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

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:
public class Main {
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);

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.
int i = 12;
do {
System.out.println(i);
i++;
}
while (i < 14);
Output:
12
13
int i = 14;
do {
System.out.println(i);
i++;
}
while (i < 14);
Output:
14




Java While Loop, ejemplo, break, do,true, else, iterator, if, =, array
Java While Loop - java

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news 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
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


HTML Image tag, code...
How to code in HTML...
HTML text tag...
HTML text, how to display...
Container responsive styles...
HTML container tag...
HTML container...
Send forgot password by mail or message ...
PHP MySQL simple login system...
Check for duplicate username live or ema...
How to create simple search engine using...
Diseño de sitio web CSS Layout...
Diseño de caja flexible CSS3...
Botones en CSS...
ID y Clase, Diferencias entre Class e Id...
Esquina redondeada CSS...
Tamaño de caja css box-sizing: border-b...
Alineación CSS...
Altura y Anchura CSS...
Bordes CSS...