+ 1

Why for loop and while loop display different answers even though the same continue statement used?

for i in range(10): square = i*i if square == 25: continue print(i) x = 0 while x < 10: square = x*x if square == 25: continue print(x) x+=1

4th Jan 2018, 3:44 PM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar
5 Respuestas
+ 9
Hmm are you sure it's 'x' instead of 'i' in your 2nd approach?
4th Jan 2018, 3:52 PM
Zephyr Koo
Zephyr Koo - avatar
0
Sr my mistake. The result is still not the same thou
4th Jan 2018, 4:00 PM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar
0
I'm not sure if it's an endless loop because without the line x+=1 of yours, the result of while loop stops at 4. Anyway, thanks for your explanation.
4th Jan 2018, 4:29 PM
Đồng Vũ Minh Phúc
Đồng Vũ Minh Phúc - avatar