Categories
java

while loop in java

 

In this post, we will learn about while loop in java with an example

while is a keyword in java used to loop in condition-based

while(condition){ 
  // your logic here
}

Example

public class WhileExample {

	public static void main(String[] args) {
		int i = 0;
		while (i < 5) {
			System.out.println("Loop Number " + i);
			i++;
		}
	}
}

Output

Loop Number 0
Loop Number 1
Loop Number 2
Loop Number 3
Loop Number 4

while loop using boolean datatype in java

https://beginnersbug.com/while-loop-using-boolean-datatype-in-java/

Leave a Reply

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