Everything2
Near Matches
Ignore Exact
Full Text
Everything2

C language flow control reference

created by Big Willy

(thing) by Big Willy (4.4 y) (print)   ?   (I like it!) Mon Jan 22 2001 at 20:50:39

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.

printable version
chaos

C++: What's this? A reference? Why does taking a programming class in a language you already know suck so much? C backslash codes C++: why input is >> and output is <<
C: A Reference Manual C++ flow The C Programming Language
spaghetti code Flow: The Psychology of Optimal Experience Mihaly Csikszentmihalyi Why Perl sucks
braces printf The Ten Commandments for C Programmers fuzzy logic
goto
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
The best nodes of all time:
The Satanic Verses
ekpyrotic universe
Civil Serf
Independence Day, Malcolm X and the Passover Seder
Watergate Salad
Kendra Smith Presents the Guild of Temporal Adventurers
Feminine hygiene products never cease to amaze
Locus of control
Big Dig
Information War is coming: whose side are you on?
Rosy fingered dawn
How to tune a guitar
Quantal Response Equilibrium
New Writeups
octillion369
Frost wyrm(person)
kalen
Three "T"s(idea)
octillion369
Undead(idea)
archiewood
Ico(fiction)
Heisenberg
Why I love Everything2(log)
octillion369
Death Knight(person)
XWiz
Are you hoping for a miracle?(review)
santo
The Host(review)
LostPsion
"Shut the Fuck Up" Theaters(idea)
beatrice
You've been slowly taking me over for nearly a year, do you know that?(idea)
Berek
YouTube(thing)
shaogo
How to Pretend to Have a Job(idea)
hapax
Les Provinciales(review)
zoeb
The Scene(review)
aneurin
Telephone Numbers for drama purposes(idea)
This page courtesy of The Everything Development Company