0% found this document useful (0 votes)
32 views12 pages

Decision Making Statements in C - 1622445973328

The document discusses different types of control statements in programming including decision making statements like if, if-else, else-if, and nested if-else statements as well as loop statements like do-while, while, and for loops. Control statements alter the flow of execution of a program compared to statements executing in order. Examples are provided for each type of control statement.

Uploaded by

keed wild
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views12 pages

Decision Making Statements in C - 1622445973328

The document discusses different types of control statements in programming including decision making statements like if, if-else, else-if, and nested if-else statements as well as loop statements like do-while, while, and for loops. Control statements alter the flow of execution of a program compared to statements executing in order. Examples are provided for each type of control statement.

Uploaded by

keed wild
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CONTROL STATEMENTS

The statements which alter the flow of execution of the program are known as
control statements. In the absence of control statements, the instructions or
statements are executed in the same order in which they appear in the program.
However, in practice we have to do certain calculations or task depending on
whether a condition or test is true or false. Similarly, sometimes it is necessary to
perform repeated actions or skip some statements. For these statements, control
statements are needed. They control the flow of program so that it is not
necessary to execute statements in the same order in which they appear in the
program.

They are two types of control statements:

Decision Making Statements

If statement

If….else statement

Else if statement

Nested if….else statement

Switch statement

Loop or Repeating construct

Do….while loop

While loop

For loop

Decision Making Statements

If Statement:

An if statement consists of a Boolean expression followed by one or more


statements.
Syntax:

If the Boolean expression evaluates to true, then the block of code inside the 'if'
statement will be executed. If the Boolean expression evaluates to false, then the
first set of code after the end of the 'if' statement (after the closing curly brace)
will be executed.

Flow Diagram:

For Example:
Output:

Another Example:

Program to find the largest number of the three:


Output:

If….else statement:

The if-else statement is used to perform two operations for a single condition.
The if-else statement is an extension to the if statement using which, we can
perform two different operations, i.e., one is for the correctness of that condition,
and the other is for the incorrectness of the condition. Here, we must notice that
if and else block cannot be executed simultaneously. Using if-else statement is
always preferable since it always invokes an otherwise case with every if
condition. The syntax of the if-else statement is given below.

Flowchart:

For Example:
Output:

Another Example:
Output:

else if statement:

The if-else-if ladder statement is an extension to the if-else statement. It is used in


the scenario where there are multiple cases to be performed for different
conditions. In if-else-if ladder statement, if a condition is true then the statements
defined in the if block will be executed, otherwise if some other condition is true
then the statements defined in the else-if block will be executed, at the last if
none of the condition is true then the statements defined in the else block will be
executed. There are multiple else-if blocks possible.
Flowchart:

For Example:
Output:

Another Example:
Output:
Nested if….else statement:

When an if else statement is present inside the body of another “if” or “else” then
this is called nested if else.

Syntax:

For Example:
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy