While loop in Java - how it works
The While Loop in Java can help you with many problems. In this practical tip, we will show you how to use the bow correctly.
Java programming: While loop
The while loop checks a condition and executes one or more statements if the result is true. If the condition is "false", the process continues after the while loop:
- Structure: while (condition) {// statement (s)}
- As long as the condition is true, the statement block is executed.
- If the condition is false, the statement block is not executed and the program continues after the While statement.
- Example: In our example, the condition is checked whether the variable "a" is less than or equal to the number 100. As long as this is the case, "a" is output and increased by 2. The program therefore outputs all even numbers between 0 and 100.
If you only want to check a condition for "true" or "false" once, then try the If statement.