Control Structure C Language
Control Structure C Language
Lesson 9
MANOLO L. GIRON
RMTU
Structure of Programming Language
Control Structures
• is a control statement and the collection of statements whose
execution it controls.
• also known as a construct, depicts the logical order of program
instructions.
• Three basic control structures are;
1. Sequence or Assignment
2. Selection
3. Repetition
4. Unconditional Branching
Structure of Programming Language
SEQUENCE OR ASSIGNMENT
CONTROL STRUCTURE
• A sequence control structure shows one or more
actions following each other in order.
• Actions include inputs, processes, and outputs.
• All actions must be executed; that is, none can
be skipped.
#include <stdio.h>
main()
{
int a , b;
a = 10;
printf( "Value of b is %d\n", (a == 1) ?
20: 30 );
ELSEIF If (control_expression 1)
{statement 1}
Else-if statements else if(control_expression 2)
are based on the {statement 2}
common else if(control_expression 3)
mathematics {statement 3}
statement, the else
{statement}
conditional
expression.
Structure of Programming Language
N-WAY, OR MULTIPLE
SELECTION
• Example using C language
• if (cows == 5 )
• { printf("We have 5 cows\n"); }
• else if (cows == 6 )
• { printf("We have 6 cows\n"); }
• else if (cows == 7 )
• { printf("We have 7 cows\n"); }
Structure of Programming Language
N-WAY, OR MULTIPLE
SELECTION
SWITCH General form is
switch( expression )
• This allows {
control to flow
case constant-expression1:
through more
statements1;
than one
[case constant-expression2:
selectable code
statements2;]
segment on a
[case constant-expression3:
single execution.
Structure of Programming Language statements3;]
[default : statements4;]
• char Grade = 'B';
• switch( Grade )
• {
• case 'A' : printf( "Excellent\n" );
• break;
• case 'B' : printf( "Good\n" ); Produce
• break; result
• case 'C' : printf( "OK\n" );
• break; Good
• case 'D' : printf( "Mmmmm....\n" );
• break;
• case 'F' : printf( "You must do better
than this\n" );
• break;
• default : printf( "What is your grade
Structure of Programming Language
anyway?\n" );
}
Repetition Control Structure
• The repetition control structure enables a
program to perform one or more actions
repeatedly as long as a certain condition is met.
• Many programmers refer to this construct as a
loop.
A GoTo L1
Ruby language.