Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShaun Kelly
5,648 Pointsinfinite while loop
Anybody know how to code an infinite while loop that will print out a number but every time the code is repeated the number will be incremented by 1. So it will look like this as shown below...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 . . . etc
This is what I have so far but the "number += number +1;" line doesn't do anything and it's printing out zero??
int i =0;
do {
int number = 0;
printf("%d", number);
number += number +1;
} while (i < 1);
1 Answer
Max Hirsh
16,773 PointsSo, it looks like the way your code is written, the integer "number" is reassigned the value 0 every time the loop cycles through. Try assigning the value 0 to number outside of the loop first, then increment the number inside the loop.