Advanced Program Flow

I.	Looping
	A.	requires iteration, doing the same thing over and over
	B.	roots of labeling in goto
		1.  loops consisted of label, statement, and a jump
			a.  label is name with colon
			b.  placed to the left of a valid C++ statment
		2.  creates spaghetti code

II.	while loops
	A.	repeats a sequence of statements as long as the starting condition 		is true 
	B.	form
		while (condition)
		{
			statement
		}
	C.	continue jumps back to the top of the loop
	D.	break immediately exits the loop
	E.	while(1) loops
		1.	a loop that will never end unless a break statement is reached
	F.	in some cases the body of a while loop may never execute

III.	do-while loops
	A.	executes the body of the loop before the condition is tested
	B.	the body executes at least once
	C.	form
		do
		{
			statements
		{
		while (expression);
	D.	continue and break work in the same way as in a while loop

IV.	for loops
	A.	standard form
		1.	for(initialization; test ;increment)
			{
				statement
			}
	B.	multiple initialization and increments - use commas
	C.	there can be null statements in for loops - use semicolon to replace 		statement
		1.  infinite for loop for(;;)
	D.	empty for loops
		1.  put a null statement, i.e., :, in the body of the loop

V.	Nested loops



VI.	switch statements
	A.	enables one to branch on any number of different values	
	B.	standard form
		1.	switch (expression)
			{ 
				case valueOne:
					statement:
					break;
				case valueTwo:
					statement;
					break;
				default:
					statement;
			}
	C.	characteristics
		1.  if no break, it will fall through to the next case
		2.  if no default, then out of switch
		3.  can only test for equality

	D.	break immediately exits 


Back to the Main Menu