November 2013
Beginner
325 pages
9h 47m
English
Sometimes you find yourself in the middle of the code block and you need to say, “Forget the rest of this run through the code block and start the next run through the code block.” This is done with the continue command. For example, what if you were pretty sure that no multiples of 3 satisfied the equation? How would you avoid wasting precious time checking those?
#include <stdio.h>
int main(int argc, const char * argv[])
{
int i;
for (i = 0; i < 12; i++) {
if (i % 3 == 0) {
continue;
}
printf("Checking i = %d\n", i);
if (i + 90 == i * i) {
break;
}
}
printf("The answer is %d.\n", i);
return 0;
}
Build and run it:
Checking i = 1 Checking i = 2 Checking i = 4 Checking i = 5 Checking i = 7 Checking i = 8 Checking i = 10 ...
Read now
Unlock full access