Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Basics of Programming

Rating
-
Sold
-
Pages
31
Uploaded on
29-04-2026
Written in
2025/2026

Learning Basics clears interviews

Institution
Course

Content preview

Unit 3 Control Flow


CONTROL FLOW
The conditional statements (also known as decision control
structures) such as if, if else, switch, etc. are used for decision-
making purposes in C programs.
They are also known as Decision-Making Statements and are used to
evaluate one or more conditions and make the decision whether to
execute a set of statements or not. These decision-making
statements in programming languages decide the direction of the
flow of program execution.
Need of Conditional Statements
There come situations in real life when we need to make some
decisions and based on these decisions, we decide what should we
do next. Similar situations arise in programming also where we need
to make some decisions and based on these decisions we will
execute the next block of code. For example, in C if x occurs then
execute y else execute z. There can also be multiple conditions like in
C if x occurs then execute p, else if condition y occurs execute q, else
execute r. This condition of C else-if is one of the many ways of
importing multiple conditions.
1. if in C
The if statement is the most simple decision-making statement. It is
used to decide whether a certain statement or block of statements
will be executed or not i.e if a certain condition is true then a block of
statements is executed otherwise not.
Syntax of if Statement
if(condition)
{
// Statements to execute if
// condition is true

,Unit 3 Control Flow


}
Here, the condition after evaluation will be either true or false. C if
statement accepts boolean values – if the value is true then it will
execute the block of statements below it otherwise not. If we do not
provide the curly braces ‘{‘ and ‘}’ after if(condition) then by default
if statement will consider the first immediately below statement to
be inside its block.
Flowchart of if Statement




Flow Diagram of if Statement
Example of if in C
C
// C program to illustrate If statement
#include <stdio.h>

,Unit 3 Control Flow


int main()
{
int i = 10;
if (i > 15) {
printf("10 is greater than 15");
}
printf("I am Not in if");
}
Output
I am Not in if


2. if-else in C
The if statement alone tells us that if a condition is true it will
execute a block of statements and if the condition is false it won’t.
But what if we want to do something else when the condition is
false? Here comes the C else statement. We can use
the else statement with the if statement to execute a block of code
when the condition is false. The if-else statement consists of two
blocks, one for false expression and one for true expression.
Syntax of if else in C
if (condition)
{
// Executes this block if
// condition is true
}
else
{

, Unit 3 Control Flow


// Executes this block if
// condition is false
}
Flowchart of if-else Statement




Example of if-else
// C program to illustrate If statement
#include <stdio.h>
int main()
{
int i = 20;

Written for

Course

Document information

Uploaded on
April 29, 2026
Number of pages
31
Written in
2025/2026
Type
Class notes
Professor(s)
Satish
Contains
All classes

Subjects

$6.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
malgesatish

Get to know the seller

Seller avatar
malgesatish KJEI
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 week
Number of followers
0
Documents
5
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions