Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 3(3.1) - Coggle Diagram
Chapter 3(3.1)
Selection control structure
simple if statements
'if' keyword is used to execute a statement
block only if a condition is fulfilled
format
if (condition)
statements;
If this condition is true, statement is executed
If it is false, statement is ignored (not executed)
else statement
format
if (condition)
statements 1;
else
statements 2;
condition expression is first evaluated. If it is evaluated to true,
statement 1 is executed, otherwise statement 2 is executed.
Else if Statement
format
if ( condition1 )
statement1 ;
else if ( condition2 )
statement2 ;
. . .
else if ( condition-n )
statement-n ;
else
statement-e ;
Nested if
used to choose between several alternatives
If an IF statement contains an IF statement as one of its possible branches, the IF statements
Switch statements
variable or expression is tested for multiple values
Consists of a series of case labels and an optional default case
break is (almost always) necessary
causes program execution to "break out" of the nearest enclosing braces
used to alter the flow of control
causes immediate exit from switch structure
will skip the remainder of a switch structure
Types of Control Structure
Sequence/sequential control structure
program segment where statements
are executed in sequence
Selection control structure
selection allows one set of
statements to be executed if a condition is true
Example :
if statements
switch statements
'If' statements
simple if statements
else statements
else if statements
Iterational/repetition
Programmer specifies an action to be repeated while some condition remains true