In chapter 7 of Objective-C Programming, the challenge is to create a program that counts backwards from 99 to 0 by 3. Additionally, every time a number is divisible by 5, it should also print "Found one!" So the output should look like:
99
96
93
90
Found One!
87
...
0
Found One!
I successfully completed the challenge with the following code:
Now, the chapter dealt with loops, which I used the "for" loop. But the chapter also introduced "break" and "continue". I struggled for a while, trying to use break and/or continue in the program, but that seemed to make it more complex than needed.
So, with the above challenge, would any of you have used the continue or break commands to achieve the same result?
Thanks!
I must say, I was kind of shocked that when I first built and ran it after typing the above, that it worked.
99
96
93
90
Found One!
87
...
0
Found One!
I successfully completed the challenge with the following code:
Code:
#include <stdio.h>
int main (int argc, const char * argv[])
{
int i;
for (i = 99; i >= 0; i -= 3) {
printf("%d\n", i);
if (i % 5 == 0) {
printf("Found one!\n");
}
}
return 0;
}
Now, the chapter dealt with loops, which I used the "for" loop. But the chapter also introduced "break" and "continue". I struggled for a while, trying to use break and/or continue in the program, but that seemed to make it more complex than needed.
So, with the above challenge, would any of you have used the continue or break commands to achieve the same result?
Thanks!
I must say, I was kind of shocked that when I first built and ran it after typing the above, that it worked.