Control Structures in C Programming
Control Structures in C Programming
PROGRAMMING
MELVIN R
B SECTION
SFS COLLEGE
BANGALORE
CONTROL STATEMENTS TYPES USED IN C
LANGUAGE
If Statements
Switch Statement
Conditional Operator Statement
Goto Statement
• Loop Statements
THE IF STATEMENTS
The instruction sets will only get executed when the evaluation of the
condition turns out to be true. In case the evaluation of the condition is
false, there will be an execution of a different instruction set. These are
also known as decision control statements
Else if ladder
Nested if
• If… else
• Simple Else or Null
THE IF… ELSE STATEMENT
• When we use the if… else statement, there occurs an execution of two different types of
statements in a program. First, if the available condition in the program is true, then
there will be an execution of the first statement. The execution of the second condition
will only occur if the condition available to us is false
• The syntax for this statement is as follows:
• If (condition 1)
• {
• Statement 1 (s1);
• }
• else
• {
• Statement 2 (s2)
• }
THE NESTED IF STATEMENT
• In this case, the condition available in the next if statement (the second statement)
will only get evaluated if the evaluation of the condition available in the first
statement turns out to be true.
• If (condition 1)
• {
• If (condition 2)
• {
• Statement 1 (s1);
• }
• Else
• {
• Statement 2 (s2)
• }
• }
THE ELSE IF LADDER
• In this statement, the execution of an array of instructions occurs only when the available condition is correct. The verification of the next
condition occurs when this first condition is incorrect.
• If (condition 1)
• {
• Statement 1 (s1);
• }
• Else if (condition 2)
• {
• Statement 2 (s2);
• }
• else if (condition 3)
• {
• Statement 3 (s3)
• }
• …
• Else
• {
THE SIMPLE ELSE OR NULL ELSE
• This condition occurs when a programmer can skip or execute a set of
various instructions on the basis of the condition value. We select a one-
way, simple statement. When the available condition gets evaluated as
true, then a set of various statements will be carried out. In case the
condition is false, then the control here will proceed ahead in the
program with the declaration mentioned below, after the program’s if
declaration
• The syntax for this statement is as follows:
• If (condition1)
•{
• Statement 1 (s1);
•}
THE SWITCH STATEMENTS
break;
break;
break;
THE CONDITIONAL OPERATOR
STATEMENTS
The C language also comes with a very unusual operator for its
programmers – the conditional operator.
int main() {
int b;
int a = 2;
return 0;}
Do While Loop
While Loop
• For Loop
DO WHILE LOOP
• The do/while loop is a variant of the while loop. This loop will execute
the code block once, before checking if the condition is true
WHILE LOOP
• The while loop in C is used to evaluate a test condition and iterate over
the loop body until the condition returns True
FOR LOOP
• The for loop in C language is used to iterate the statements or a part of
the program several times.