Does >/< actually mean >=/<= in a while loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does >/< actually mean >=/<= in a while loop?

Python while loop problem i = 0 x = 0 While i < 4: x+ = i i+ = 1 print(x) Steps taken 1. x = 0 i = 1 2. x = 1 i = 2 3. x = 3 i = 3 4. x = 6 i = 4 The correct answer was 6 So my question is does this < actually mean <= since it stops on the loop when i = 4? Or do you stop halfway through the loop when x = 6 but before you solve i+ to produce a 4?

12th Jan 2022, 5:44 PM
NW1121
1 Answer
+ 1
It stops at i = 4 because the condition is "while i is less than 4" Instead, i <= 4 means "while i is less than OR EQUAL to 4", so it will be executed one more time and "i" will end up being 5
12th Jan 2022, 6:05 PM
CGM
CGM - avatar