PRO
M.
asked

Expert
Abhay Jajodia answered
It’s not a bug. Your count never changes, so count <= 3 stays true forever.
Buggy code:
#include
int main() {
int count = 1;
while (count <= 3) {
printf("I am inside a loop.\n");
printf("Looping is interesting.\n");
}
return 0;
}
Output (repeats forever):
I am inside a loop.
Looping is interesting.
...
Fix:
#include
int main() {
int count = 1;
while (count <= 3) {
printf("I am inside a loop.\n");
printf("Looping is interesting.\n");
count = count + 1;
}
return 0;
}
Output:
I am inside a loop.
Looping is interesting.
I am inside a loop.
Looping is interesting.
I am inside a loop.
Looping is interesting.
If you have more questions, I am here to help.
C
This question was asked as part of the Learn C Programming course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
