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!
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
Bilal Junaidy1,775 Points
Why isnt the test condition that x<= 10 being implemented?
Below are two set of codes which look almost exactly the same. For the first one both the condition that x <= 10 and y >= 1 are being followed when I print the results. But for the second code the condition that x <= 10 and y >= 1 is not being followed, in fact it fulfill the condition for y >= 1 but not for x<=10. could someone please explain me why?This link might be helpful https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#The-for-Statement int x, y; for (x = 1, y = 10; x <= 10 && y >= 1; x+=2, y--) printf ("%d %d\n", x, y);
int x, y; for (x = 1, y = 10; x <= 10 , y >= 1; x+=2, y--) printf ("%d %d\n", x, y);
James Andrews7,245 Points
YOu should read the link that you provided where it says.
Perhaps confusingly, you cannot use the comma operator (see The Comma Operator) for monitoring multiple variables in a for statement, because as usual the comma operator discards the result of its left operand.
You need to use the && operator.