Post

@PythonPr Output: 1 2 3 4
else runs because the loop ends normally (no break).
English

@PythonPr The while loop runs 3 times and outputs 1,2,3. Since the loop completed normally, the else statement runs. After 3 was output in the loop, x did become 4 but that stopped the loop. So, 1 2 3 4
English

@PythonPr Answer: 1 2 3 4
while loops can have an else -- and most don't know it!
For beginners: else on while/for runs when no break occurred. Use it to detect "loop finished cleanly" -- no flag variable needed.
English

@PythonPr 1 2 3
4
Else block will run when while loop condition become false.
English

@PythonPr Output: 1 2 3 4
else runs because the loop ends normally (no break)..
English







