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 trial
Joey LoForti
Courses Plus Student 1,864 PointsOjective-C Loops Quiz
I just somehow completed the loops quiz with a perfect score but I really have no idea what I'm doing. I understood enough to pass the quiz but I have no idea what I'm doing at any useful practical level. Can someone please explain the code below in real english so I can understand it? I appreciate all the help I can get. See below..
char letters2[] = {'a', 'b', 'c'};
int z =0;
while (z < 3) {
printf("letter %d is %c\n", z, letters2[z]);
++z;
2 Answers
Charles Massry
12,253 Pointsalright
char letters2[] = {'a', 'b', 'c'}; You are declaring an array of characters.
int z =0; You are declaring an integer 0.
while (z < 3) you are creating a while loop that continues the loop while the condition z < 3 remains true.
printf("letter %d is %c\n", z, letters2[z]); you are printing the integer z and the place in the array that corresponds to the integer for example if z = 0 it will display 'a' and if z = 1 it will display 'b', that is what letters2[z] does.
++z; You are incrementing z so you do not have what is called an infinite loop and it properly displays the place in the array.
Joey LoForti
Courses Plus Student 1,864 PointsThank you I appreciate the time you took to explain that.
Véronique Bellamy
20,810 PointsVéronique Bellamy
20,810 PointsAdded some markdown code so your code displays better. :)