Getting Started

(lily) #1

Chapter 5: C Control Flow


A continue statement causes the loop to skip the following statements in the block
and start the loop over again. You won’t see this often, but it can come in handy
for amazingly complex decision loops. Gurus use it a lot for job security.


Goto and Labels


There are those who would burn you at the stake for using ‘goto’. I’m not one of
those, but I won’t throw water on you when some other C dude sets you on fire
for this heresy. The goto statement is probably the laziest, most unnecessary,
confusing, and potentially harmful thing you can stick in your code. It allows you
to jump all over the place without regard to logic or common sense, creating the
infamous ‘spaghetti code’. But I have used it on occasion to escape a deeply
nested loop as a quick fix for a bug when I didn’t have time to rewrite the code
like it should have been written in the first place. But I have never shown anyone
such code; I have my pride you know. Anyway, the goto statement causes a jump
to a label as follows:


while(expression){
for(expression;expression;expression){
do{
if(expression){
switch(expression){
case expression:
if(expression) expression;
else goto GETMEOUTOFHERE!;
break;
case expression:
expression;
break;
default:
break;
}
}
}while(expression)
}
}


GETMEOUTOFHERE!:
// Put more code here, or better yet, rewrite the nested loops above.

Free download pdf