why is it printing 3? Although in theory it should not | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why is it printing 3? Although in theory it should not

i = 1 while i<=5: print(i) i+=1 if i==3: print("Skipping 3") continue

21st Aug 2020, 10:34 AM
иван
иван - avatar
3 Answers
+ 7
it skip 3 after print 3. see the logic error there ?
21st Aug 2020, 10:36 AM
Rei
Rei - avatar
+ 2
the code works from top to bottom. you have the check if the value == 3 AFTER your call to print each value. just put the if statement first
21st Aug 2020, 10:37 AM
Slick
Slick - avatar
+ 1
many thanks to all!
21st Aug 2020, 11:20 AM
иван
иван - avatar