I have a feeling I'm gonna feel really stupid here, but I'm just learning about using ++
and --
to increment and decrements variables for while loops, and was wondering why this piece of code works and why this doesn't?
Bad code:
int ctr = 0;
while (ctr < 10)
printf("%d",ctr);
ctr=ctr+1;
The bad code outputs zeros indefinitely.
Working code:
int ctr=0;
while (ctr++ < 10)
printf("%d",ctr);
The idea is for the output to be 012345678910 but even in the working code, it starts at 1 and goes to 10, instead of starting at 0. Even though the initial value of ctr is 0.