Home
|
NovaMind Home
|
Friends
|
0 New Messages
|
Profile
|
? Help
Login
|
Sign Up
Search:
Mind Maps
People
Subscribe
Syntax
C Programming Language
>
Flow Control
>
loops
>
while statement
>
Map Branches
loops
while statement
Syntax
while ( expression ) statement
Driving Factors
Before the Loop
Initialization
In the Loop
Modification
value that affects the loops expression
Within expression
while ( ++variable ) statement
After expression
while ( expression ) ........ ........ ++variable
Counter
Variable
Holds Value of # of loops
Termination
causes loop to terminte
a condition
purpose
repeated execution of a statement or statement block
as long as expression is true
for statement
syntax
for ( expression1 ; expression2 ; expression3 ) statement
Initialization
expression1
evaluated once - beginning
Termination
expression2
evaluated each time - beginning
Modification
expression3
evaluated each time - bottom - post statement execution
infinite loop
for ( ; ; ) DoSomethingForever()
no initialization, termination, and modification
considered bad form
comparison
for loop as while loop
expression1; while ( expression2 ) { statement expression3; }
for loop and while loop are interchangable
do statement
syntax
do statement while ( expression ) ;
comparison
unlike while and for loop
expression is evaluated at the bottom of loop
consequence of bottom evaluation
loop statement always executed at least once
selection statements
if statement
Types
Regular (no else)
Syntax
if (expression) statement
Statements are executed/triggered only if expression evaluates to "not false"
If with else
Syntax
if ( expression ) statement else statement
if expression = not false
execute statements after expression and ignore statements after else
if expression = false
execute statements after else
Value
"If statement expressions" can evaluate to false or not false
false and not false have values
If the expression evaluates to 0
expression is false
If Statment is not triggered
If expression does not evaluate to 0
expression is not false
If Statement is triggered
Purpose
One time execution of a statement or statement block
based on value of expression
switch statement
syntax
switch ( expression ) { case value1: statement break; case value2: statement break; case valueX: statement break; default: statement }
case value has to be constant or single-byte characters
case value cannot be a variable or mutiple-byte character strings
purpose
uses value of expression to determine which case is executed
case with no statements
used to make two cases execute the same statement
switch ( numberOfEggs ) { case 1: case 2: HardBoilThem(); break; case 3: MakeAnOmelet(); default: }
case 1 and 2 will execute the same statement - break is missing in case 1
break statement and fall-through
not adding breaks in the cases
adds more functionality as you fall-through the cases
switch ( myVar ) { case 1: DoSometimes(); case 2: DoFrequently(); default: DoAlways(); }
if myVar is case1 all functions get executed
if myVar is case2 then functions in this case and default get executed
if myVar case is not 1 or 2 then function after default get executed
Comments
►
0 branch comments of 0 total for this map and 0 for the whole document
You must be logged in to post comments