0

why are the outputs of these two codes starting from different digits?

int num = 5; while (num > 0) { if (num == 3) break; printf("%d\n", num); num--; } int num = 5; while (num >0){ if (num ==3) continue; printf("%d\n",num); num--; }

14th Jul 2019, 4:09 PM
Aniruddha Roy
Aniruddha Roy - avatar
5 Answers
0
break means stop the loop. there's no next itteration, just stop. continue means skip this one. but the next one still able to run
14th Jul 2019, 4:25 PM
Taste
Taste - avatar
0
i have understood that..but my ques is why the starting of these two codes' outputs are from different digit? the first one is starting from 5 but the second one is from 4.why?
15th Jul 2019, 2:29 AM
Aniruddha Roy
Aniruddha Roy - avatar
0
beside the second one can cause infinite loop. no it doesnt
15th Jul 2019, 5:28 AM
Taste
Taste - avatar
0
i can't understand that,bro.
15th Jul 2019, 8:14 AM
Aniruddha Roy
Aniruddha Roy - avatar
0
here is the thing while(num>0){ if(num==3) continue; num--; } when ever the num reach 3, it'll hit continue and skip the decrement part, and still at 3. then at thenext itteration it'll hit continue again and skip decrement part. its neverending loop.
15th Jul 2019, 8:16 AM
Taste
Taste - avatar