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--; }
5 Réponses
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
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?
0
beside the second one can cause infinite loop.
no it doesnt
0
i can't understand that,bro.
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.