New course! Every coder should learn Generative AI!
Try a free lesson+ 1
continue;
why if we num -- after the continue ,we have infinited loop??
4 Answers
+ 5
num==5
so num>0 is true
num==3 is false
We print 5 and we decrement num
So num==4
num>0 is true
num==3 is false
So we print 4 and we decrement num
Then num==3
num>0 is true
num ==3 is TRUE
continue is executed so we go to the while condition
num didn't change and it equal to 3
num>0 is true
num==3 is true so continue is executed
And it will repeat infinitely because num==3 and it will never change!!
+ 2
blind magnet num is always 3 when you use continue , continue throws back the control to the start of while loop but since num never increments you get the condition checking if num==3 again till infinite times
+ 1
#include <stdio.h>
int main() {
int num = 5;
while (num > 0) {
if (num == 3)
continue;
printf("%d\n", num);
num--;
}
}
why doesn`t this code work??
0
I don't understand what you mean. Can you explain in more details?