continue; | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

continue;

why if we num -- after the continue ,we have infinited loop??

6th Sep 2020, 6:38 AM
blind magnet
blind magnet - avatar
4 Réponses
+ 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!!
6th Sep 2020, 7:12 AM
CHERIEF Houcine Abdelkader
CHERIEF Houcine Abdelkader - avatar
+ 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
6th Sep 2020, 7:05 AM
Abhay
Abhay - avatar
+ 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??
6th Sep 2020, 6:46 AM
blind magnet
blind magnet - avatar
0
I don't understand what you mean. Can you explain in more details?
6th Sep 2020, 6:41 AM
你知道規則,我也是
你知道規則,我也是 - avatar