Control/Lopping Statement : For loop and While loop

Published: (February 5, 2026 at 04:29 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

What are loops?

Loops are used to repeat a block of code.
Instead of writing the same statements many times (e.g., printing a message 100 times), a loop can execute the code repeatedly until a specified condition is met.


While Loop

A while loop evaluates the expression inside the parentheses () before each iteration.

  1. If the expression evaluates to true, the code inside the loop is executed.
  2. After the body runs, the expression is evaluated again.
  3. This process continues until the expression evaluates to false, at which point the loop stops.

Example

int i = 1;
while (i = 'a' && ch = 'a' && ch <= 'z') {
    System.out.println("Good! you have entered a vowel");
    continueLoop = false;
} else {
    System.out.println("Entered Character is not vowel");
}
}
sc.close();
}
}
Back to Blog

Related posts

Read more »

Switch Case

What is a switch statement? The switch keyword in Java is used to execute one block of code among many alternatives. The expression is evaluated once and compa...

Operators

What are Operators in Java? Operators are symbols used to perform operations on variables and values. Types of Operators in Java - Arithmetic Operators - Assig...