Java While Loop

The Java while loop is used to iterate a part of the program repeatedly until the specified Boolean condition is true. As soon as the Boolean condition becomes false, the loop automatically stops.

The while loop loops through a block of code as long as a specified condition is true

Syntax :

while (condition) {
  // code block to be executed
}

 

Example :

import java.util.*;

public class Main {
public static void main(String[] args) {
int p = 0;
while (p < 7) {
System.out.println("The number is :"+p);
p++;
}
}
}

Output :

Output:

The number is :0
The number is :1
The number is :2
The number is :3
The number is :4
The number is :5
The number is :6

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

43381