![]() |
VOOZH | about |
While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed.
Here, the condition for while will be True as long as the counter variable (count) is less than 3.
Hello Geek Hello Geek Hello Geek
while expression:
statement(s)
Parameters:
An infinite loop is a loop that keeps running continuously because its condition always remains True. Such loops do not stop on their own and continue executing until the program is manually terminated.
Explanation: Here, the condition age > 19 is always True because the value of age never changes inside the loop. Therefore, the loop runs infinitely.
Continue statement is used to skip the current iteration of the loop and move directly to the next iteration.
g k f o r g k
Explanation: Here, whenever the character is 'e' or 's', the loop skips printing it and continues with the next character.
Break statement is used to immediately terminate the loop when a specific condition becomes True.
g
Explanation: Here, the loop stops as soon as it encounters the character 'e' or 's'.
pass statement is a null statement. It does nothing when executed and is mainly used as a placeholder for future code.
Value of i : 13
Explanation: Here, the loop runs through all characters of the string, but the pass statement performs no action inside the loop body.
else block in a while loop executes only when the loop finishes normally without encountering a break statement. In first example, loop completes all iterations, so the else block executes. In second example, loop stops because of break, so the else block is skipped.
1 2 3 4 No Break 1