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
sieder villareal
4,016 Pointsobjective-C question
for(int m=1;m <= 200; m++){
int divisibleByFive;
divisibleByFive = 5;
NSLog(@"%d", m);
if((m % divisibleByFive) == 0) {
NSLog(@"divisible by %d = %d",divisibleByFive, m);
}
}
I coded this and still don't understand the if statement's condition. why is it is-equal to 0, to get the divisibility. Thanks!
1 Answer
Francisco Navarro
14,185 PointsHi!
The result of "m % divisibleByFive" is the remainder of the division (not the quotient as you might think). So the if statemen says: If the remainder of some number divided by 5 is 0 that means is a divisible number, everything else (a remainder from 1 to 4 in this case) is not divisible.
sieder villareal
4,016 Pointssieder villareal
4,016 PointsThank youuu!! xx