Why is the output showing " time limit exceeded" when i run this program ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is the output showing " time limit exceeded" when i run this program ?

#include <stdio.h> int main() { int num = 5; while (num > 0) { if (num == 3) continue; printf("%d\n", num); num--; } }

10th Oct 2019, 2:16 PM
Sk. Ahmed Razha Khan
Sk. Ahmed Razha Khan - avatar
1 Answer
+ 5
That's because of the continue statement inside if block. When num gets equal to 3, the if condition evaluates to true so the below code is skipped. So, there will be no decrement in the value of num. So, the num will have again the same value(3) and below code will be skipped. This way it became an infinite loop, num will never get decremented to 0.
10th Oct 2019, 3:00 PM
blACk sh4d0w
blACk sh4d0w - avatar