Please help me understand. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help me understand.

#example 1 counter = 0 while counter < 8: counter += 10 print("#") #example 2 counter = 0 while counter < 8: print("#") counter += 10 Why does example 1 and 2 have the same output. Shouldn’t there be no # printed for example 1. Because the first loop add 10 before meeting the condition. However example 2 makes more sense.

20th Oct 2021, 8:36 PM
Jenkins
1 Answer
0
The condition is checked before an iteration. The fact that during the iteration the value changes so the condition is no longer fulfilled plays no role for that iteration. The condition is not checked during an iteration.
20th Oct 2021, 9:05 PM
Simon Sauter
Simon Sauter - avatar