0

Why do I get 1 as output in case of if while I get 1,2,3,4,5 in case of while

https://code.sololearn.com/cTPxpjI0079N/?ref=app

8th Jul 2020, 6:59 AM
Ifham Khwaja
5 Antworten
+ 2
If is a conditional statement. It runs the code only once while while is a loop and it would keep running till the condition is met.
8th Jul 2020, 7:04 AM
Arnesh
Arnesh - avatar
+ 1
Because you didn't print i after increasing it
8th Jul 2020, 7:21 AM
Arnesh
Arnesh - avatar
0
But why do I get 1 why don't I get 2 ( i + 1 == 2)
8th Jul 2020, 7:11 AM
Ifham Khwaja
0
Ifham Khwaja because you print the value of i before increasing its value. If you have to print 2 use print statement after increasing the value of i.... i=1 if i<=5: i+=1 print(i) print('Finished!')
8th Jul 2020, 7:23 AM
Sanjyot21
Sanjyot21 - avatar
0
Thanks a lot guys
8th Jul 2020, 11:19 AM
Ifham Khwaja