BAB VI
Statement-Level
Control Structures
Selection Statements
Two- way Selectors (IF Statement)
if
control_expression
then clause
else clause
Multiple-way selectors (Switch Case)
Design choices for C’s switch statement
1. Control
expression can be only an integer type
2. Selectable
segments can be statement sequences, blocks, or compound statements
3. Any number of segments can be executed in
one execution of the construct (there is no implicit branch at the end of
selectable segments)
4. default
clause is for unrepresented values (if there is no default, the whole statement
does nothing).
Iterative Statements
The repeated execution of a statement or compound statement
is accomplished either by iteration or recursion.
Counter-Controller Loops
·
A counting iterative statement has a loop
variable, and a means of specifying the initial and terminal, and stepsize
values.
Logically-Controlled Loops
·
Repetition control is based on a Boolean
expression
·
There are posttest and pretest logical controlled
loops
·
Posttest logical controlled loop always do the
loop a least once. And the statement checked after the looping is done not
before.
·
Pretest logical controlled loop test the
statement control of the loop, if it’s true then do the loop, if it’s false
then stop the looping
User-Located Loop Control Mechanisms
·
Sometimes it is convenient for the programmers
to decide a location for loop control (other than top or bottom of the loop).
·
Continue :
that skips the remainder of the current iteration, but does not exit the
loop
·
Break :
Immediately exit the loop.
Tidak ada komentar:
Posting Komentar