Java While Loop
Java While Loop is used to iterate a program code several times especially when the number of iterations is not fixed.
Example
Java While Loop Syntax
[
while(condition)
{
//code to execute
}
]
Java While Loop Example
[
public class JavaWhileLoop { public static void main(String args[]) { int score=1; while (score<=10) { System.out.println("The Score is "+score); score++; } } }
]
Output:
Java Infinitive While Loop
To create infinitive java while loop we just pass boolean true as the condition.
Syntax
[
while(true) { //code to execute }
]
Example
[
public class JavaInfinitiveLoop { public static void main(String args[]) { while(true) { System.out.println("Infinitive Java While loop"); } } }
]