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
Look at this mess the Death Borg made!
Filibuster
The Gunfighters
Jim Crow
Les Fleurs du Mal
transsexual
Concorde
Give me assembly language, or give me death!
journalism and technology
Bill Clinton
Life grit homespun art
The Endangered Species Act
My brother made $700 in 3 hours by sitting in front of a grocery store
women's clothing size woes
New Writeups
antigravpussy
One fly amongst many(person)
sam512
Moon Base Shackleton, 1978(fiction)
Pavlovna
toy boy(person)
XWiz
tear jerker(review)
Heitah
Anarchy is Order(idea)
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
SwimmingMonkey
Conversations with Fo Fo, the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
This page courtesy of The Everything Development Company