Control/Lopping Statement : For loop and While loop
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.
- If the expression evaluates to
true, the code inside the loop is executed. - After the body runs, the expression is evaluated again.
- 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();
}
}