This is a quick reference of all the C flow control statements that exist and all the forms they take. Note that all of these statements except for switch can take the form of the first if statement form that I demonstrate (a single statement with no curly braces). Remember also that white space and formating are not rigid in C. I adhere to my own style, which may or may not be in accordance with common practices.

if statement
if (expression) statement;

if (expression) {
	statement;
} else {
	statement;
}

if (expression) {
	statement;
} else if (expression) {
	statement;
} else {
	statement;
}
for statement
for (initialization; conditional test; increment) {
	statement;
}
while and do while statements
while (expression) {
	statement;
}

do {
	statement;
} while (expression);
switch statement
switch (variable) {
	case constant1;
		statement;
		break;
	case constant2;
		statement;
		break;
	default:
		statement;
		break;
}
goto statement
mylabel: statement;
goto mylabel;
Please note that goto is the lamest statement ever and you should not use it, except in rare cases within deeply nested loops where a little discrete jumping around is absolutely necessary. Try to avoid it. And for the uneducated, the subtle difference between while and do while is that do while will always execute the statements between the curly braces once before evaluating the expression.

Log in or register to write something here or to contact authors.