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

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.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...