In this chapter we will see while loop in Java it is used to to iterate path of the program on certain condition. in an another word run a block of code with a specified condition is called loop. with while loops are also the same condition applies.
While loop
if condition is true then while will execute the block of code.
syntax:
while (condition) {
// code block to be executed
}
Example:
public class JavaApplication {
public static void main(String[] args) {
int i = 0;
while (i < 4) {
System.out.println(i);
i++;
}
}
}
output:
run:
0 1 2 3 |
Thanks, May this example will help you.