Professional Documents
Culture Documents
Assignment Operators
Increment/Decrement Operators
Control Structures in C
Enable the programmer to control the flow of
the program and the sequence by which the
inputted commands are to be executed
Types:
1. Sequence Structure
Statements are executed in the order by which they are written
2. Selection Structure
if, if-else statements, switches
Selection Structures
If, if-else, nested if-else, switch
Selection Structures
1. if statement
- single-selection structure
2. if-else statement
- double-selection structure
3. switch
- multiple-selection structure
if Selection Structure
Allows a program to execute a (set of)
command(s) if the relational condition statement
is satisfied
Syntax:
if (condition statement)
{
body statement;
}
CE 26 Lecture 3 Control Structures in C
if Selection Structure
Repetition Structures
(Loops)
for, while,do-while
Repetition Structures
Means of Repetition:
1. Counter-controlled (definite repetition)
Counter-controlled variable counts the
number of specified repetitions
2. Sentinel-controlled (indefinite repetition)
Sentinel serves as the lookout/guard since
the no. of repetitions is unknown or is
dependent on data that will be inputted by
the user
CE 26 Lecture 3 Control Structures in C
Repetition Structures
1. for
-repeats a statement or compound statements a
specified number of times
2. while
-executes a statement or a block of statements until a
specified expression evaluates to false.
3. do-while
-similar with while except that the condition is evaluated
after each execution of the loop; executes the
statement at least once
CE 26 Lecture 3 Control Structures in C
Syntax
initialization;
while(test condition)
{
compound statement;
increment;
}
References:
Lecture Notes and Presentations by Dr. Eric
Tingatinga and Rahf Alvarez
C How to Program: Introducing C++ and Java,
3rd Ed. By Deitel&Deitel.