This:
CODE
for (i=j+k;; j+k)
break;
is not very helpful. I don't even think it would compile.
the syntax for a for-loop is as follows:
for (<initialize loop>; <condition>; <step>) statementthe inner parts of the for-loop are three expressions. The first one is used to set the loop up, it is executed before anything else. The next expression is evaluated as a boolean expression (either true or false) and it can be though of as:
loop as long as <condition> is true.
The last expression is evaluated at the bottom of the loop (just before it loops back to the top). Normally the three expressions are linked -- that is that the first one sets thing up, and the third one will eventually cause the second expression to evaluate to false.
so for example to count to 10:
CODE
for (int i=1; i < 10; i++) {
printf("%d", i);
}
to count the number of characters in a cstring:
CODE
char *str = "I had a tiny turtle his name was Tiny Tim.";
int length = 0;
for (char* ptr = str; str != 0x00; str++) length++;
this can be simplified to:
CODE
char *str = "I had a tiny turtle his name was Tiny Tim.";
int length;
char * ptr;
for ((ptr = str, length = 0); str != 0x00; (str++, length++));
Some programmers like to use "infinite" loops using the break statement to exit the loop. Although there is nothing WRONG with this, you should use the control structures as they were designed. You should use the ending condition if it can be used. The break statement can become very complicated to use and often causes problems when code is updated.