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();
}
}
0 views
Back to Blog

Related posts

Read more »

제어 함수

조건문 Conditional Statement 조건에 따라 특정 동작을 하도록 하는 프로그래밍 명령어 명제 - 참 또는 거짓을 객관적이고 명확하게 판별할 수 있는 문장이나 식 관계 연산자 - x == y - x != y 논리 연산자 - X and Y - X or Y - not X IF...

Mock interview-2

Interview Questions 1. Tell me about yourself? 2. Why move from Mechanical Engineering to IT? 3. If Mechanical Engineering was your first choice, why choose an...

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...