Control Structures
Control Structures
1/2
LESSON 4: Control Structures
Study online at https://quizlet.com/_dbvl9r
One or more sections in the for statement can be omitted, if
necessary.
true Empty for loop is possible
true Declare loop control variable inside the for
This is a good, solid looping process with applications to numer-
while loop
ous situations
This is a good choice when you are asking a question, whose
do-while loop
answer will determine if the loop is repeated
This is a good choice when the number of repetitions is known or
for loop
can be supplied by the user
Counter-Controlled Loop, Sentinel-Controlled Loop Classification of LOOPING PROCESS
Classification of LOOPING PROCESS used to read in and
Counter-Controlled Loop process a sequence of data items when you know in advance the
number of items to be read
Classification of LOOPING PROCESS where the user enters a
"unique" data value, called a sentinel value, after the last data
Sentinel-Controlled Loop,
item; the loop repetition condition tests each data item and causes
the loop to exit when the sentinel value is read.
return 0;, exit();, break;, continue;, How to end a program or loop earlier than its normal termination?
It is possible to end a program (or function) prior to its normal
return 0;
termination by using an "extra" return0; statement.
- It requires the Standard Library header file, stdlib.
-The format is: exit (value);
exit(); -Using exit (1); returns a value of 1 to the IDE indicating that an
error must have occurred. This process is often used for error
trapping.
- Gets you out of a loop.
-The program continues with the next statement immediately fol-
break;
lowing the loop.
- It does not break out of a "nested loop" (a loop within a loop)
- performs a "jump" to the next test condition in a loop
-The continue statement may be used ONLY in iteration state-
continue;
ments (loops). It serves to bypass, or jumpover, certain iteration
sections of a loop.
Zero Iteration Loop, Flag-controlled Loop, Nested Loop Other types of LOOPING
There may be instances where the while loop will not execute
Zero Iteration Loop
because the test failed (False condition).
- are used to control the execution of loop.
- The value of the flag is initialized (if not assigned a value, it will be
Flag-controlled Loop
false) prior to loop entry and is redefined when a particular event
occurs inside the loop.
- placing of one loop inside the body of another loop
- most commonly used in for loops
Nested Loop
-When working with nested loops,the outer loop changes only
after the inner loop is completely finished (or is interrupted).
2/2