0

Mistake in tutorial?

The third exercise in the python 3 tutorial - while loops looks like this: “How many numbers does this loop print? i = 5 while true: print(i) i - 1 = i if i <= 2: print(break) _” The correct answer for this Is supposedly 3, but since the loop is set to run while i equals 5, wouldn’t it stop after the first cycle?

27th Jul 2019, 10:38 PM
Jan
2 Answers
0
i is set to 5, then the loop runs until a break condition. It's while true, so is basically an infinite loop unless you break out of it. = is an assignment, == is the comparison. You would need while i == 5 for the situation you describe
27th Jul 2019, 10:44 PM
Dan Walker
Dan Walker - avatar
0
I see, thanks. This had me really confused...
27th Jul 2019, 10:45 PM
Jan