SlideShare a Scribd company logo
1 of 14
Control Flow Structure
• Control structures form the basic entities of a “structured
programming language“.
• Control structures are used to alter the flow of execution of the
program.
There are three types of control structures available in C and C++
• Sequence structure (straight line paths)
• Selection structure (one or many branches)
• Loop structure (repetition of a set of activities)
Sequence structure
Selection structure
If statement
if (condition)
{
Program statements;
}
If else statement
if (condition)
{
Program statements;
}
Else
{
Program statements;
}
Switch statement
switch (expression)
{
Case value_1;
Statement1;
Break;
Case value_2;
Statement2;
break;
Default:
Statementx;
break
}
Problem Statement
If the integer entered by user is 1 – output on screen “UNITED STATES”.
If the integer is 2 – output “SPAIN”, If the integer is 3 output “INDIA”. If
the user enters some other value – output “WRONG ENTRY”.
Loop structure (repetition of a set of activities)
• In programming, there exists situations when you need to repeat
single or a group of statements till some condition is met. Such as -
read all files of a directory, send mail to all employees one after
another etc. These task in C programming is handled by looping
statements.
• Looping statement defines a set of repetitive statements. These
statements are repeated with same or different parameters for a
number of times. Looping statement is also known
as iterative or repetitive statement.
C supports three looping statements.
• for loop
• while loop
• do...while loop
For Loop
• For loop is an entry controlled looping statement. It is used to repeat set of
statements until some condition is met.
• Looping statements whose condition is checked prior to the execution of
its body is called as Entry controlled loop.
Syntax of Loop
for(variable-initialization ; condition ; variable-update)
{
// Body of for loop
}
/** * C program to print natural numbers from 1 to
10. */
#include <stdio.h>
int main()
{
/* Declare loop counter variable */
int count; /* Run a loop from 1 to 10 */
for(count=1; count<=10; count++)
{ /* Print current value of count */
printf("%d ", count);
}
return 0;
}
While Loop
Start
Initializing n=1
n < 10
Stop
Print n
n = n + 1
True
False
Do While Loop
Start
Initializing n=1
n < 10
Stop
Print n
n = n + 1
True
False

More Related Content

Similar to NRG 106_Session 4_CLanguage.pptx

control structure by shuja ahmad
control structure by shuja ahmadcontrol structure by shuja ahmad
control structure by shuja ahmadInocentshuja Ahmad
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJanCarlBriones2
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxSKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxLECO9
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxLikhil181
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptganeshkarthy
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 

Similar to NRG 106_Session 4_CLanguage.pptx (20)

Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
control structure by shuja ahmad
control structure by shuja ahmadcontrol structure by shuja ahmad
control structure by shuja ahmad
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptx
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Session 3
Session 3Session 3
Session 3
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
C++ rajan
C++ rajanC++ rajan
C++ rajan
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
control structure
control structurecontrol structure
control structure
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Ch05
Ch05Ch05
Ch05
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 

More from KRIPABHARDWAJ1

NRG 106_Session 6_String&Pointer.pptx
NRG 106_Session 6_String&Pointer.pptxNRG 106_Session 6_String&Pointer.pptx
NRG 106_Session 6_String&Pointer.pptxKRIPABHARDWAJ1
 
NRG 106_Session 2_FlowCharts.pptx
NRG 106_Session 2_FlowCharts.pptxNRG 106_Session 2_FlowCharts.pptx
NRG 106_Session 2_FlowCharts.pptxKRIPABHARDWAJ1
 
NRG 106_Session 1_History.pptx
NRG 106_Session 1_History.pptxNRG 106_Session 1_History.pptx
NRG 106_Session 1_History.pptxKRIPABHARDWAJ1
 
Dams- Politics of Displacement (Domestic) (1).pptx
Dams- Politics of Displacement (Domestic) (1).pptxDams- Politics of Displacement (Domestic) (1).pptx
Dams- Politics of Displacement (Domestic) (1).pptxKRIPABHARDWAJ1
 
Rain Water Harvesting.pptx
Rain Water Harvesting.pptxRain Water Harvesting.pptx
Rain Water Harvesting.pptxKRIPABHARDWAJ1
 
FINAL PPT (HYDROLOGY) WATER HARVESTING.pptx
FINAL PPT  (HYDROLOGY) WATER HARVESTING.pptxFINAL PPT  (HYDROLOGY) WATER HARVESTING.pptx
FINAL PPT (HYDROLOGY) WATER HARVESTING.pptxKRIPABHARDWAJ1
 
SOURCES OF POPULATION DATA.pptx
SOURCES OF POPULATION DATA.pptxSOURCES OF POPULATION DATA.pptx
SOURCES OF POPULATION DATA.pptxKRIPABHARDWAJ1
 
French & Industrial Rev..pptx
French & Industrial Rev..pptxFrench & Industrial Rev..pptx
French & Industrial Rev..pptxKRIPABHARDWAJ1
 

More from KRIPABHARDWAJ1 (10)

gis assgnmnt.pptx
gis assgnmnt.pptxgis assgnmnt.pptx
gis assgnmnt.pptx
 
NRG 106_Session 6_String&Pointer.pptx
NRG 106_Session 6_String&Pointer.pptxNRG 106_Session 6_String&Pointer.pptx
NRG 106_Session 6_String&Pointer.pptx
 
NRG 106_Session 2_FlowCharts.pptx
NRG 106_Session 2_FlowCharts.pptxNRG 106_Session 2_FlowCharts.pptx
NRG 106_Session 2_FlowCharts.pptx
 
NRG 106_Session 1_History.pptx
NRG 106_Session 1_History.pptxNRG 106_Session 1_History.pptx
NRG 106_Session 1_History.pptx
 
Dams- Politics of Displacement (Domestic) (1).pptx
Dams- Politics of Displacement (Domestic) (1).pptxDams- Politics of Displacement (Domestic) (1).pptx
Dams- Politics of Displacement (Domestic) (1).pptx
 
Rain Water Harvesting.pptx
Rain Water Harvesting.pptxRain Water Harvesting.pptx
Rain Water Harvesting.pptx
 
FINAL PPT (HYDROLOGY) WATER HARVESTING.pptx
FINAL PPT  (HYDROLOGY) WATER HARVESTING.pptxFINAL PPT  (HYDROLOGY) WATER HARVESTING.pptx
FINAL PPT (HYDROLOGY) WATER HARVESTING.pptx
 
SOURCES OF POPULATION DATA.pptx
SOURCES OF POPULATION DATA.pptxSOURCES OF POPULATION DATA.pptx
SOURCES OF POPULATION DATA.pptx
 
French & Industrial Rev..pptx
French & Industrial Rev..pptxFrench & Industrial Rev..pptx
French & Industrial Rev..pptx
 
Landslide.pptx
Landslide.pptxLandslide.pptx
Landslide.pptx
 

Recently uploaded

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

NRG 106_Session 4_CLanguage.pptx

  • 2. • Control structures form the basic entities of a “structured programming language“. • Control structures are used to alter the flow of execution of the program.
  • 3. There are three types of control structures available in C and C++ • Sequence structure (straight line paths) • Selection structure (one or many branches) • Loop structure (repetition of a set of activities)
  • 6. If statement if (condition) { Program statements; } If else statement if (condition) { Program statements; } Else { Program statements; } Switch statement switch (expression) { Case value_1; Statement1; Break; Case value_2; Statement2; break; Default: Statementx; break }
  • 7. Problem Statement If the integer entered by user is 1 – output on screen “UNITED STATES”. If the integer is 2 – output “SPAIN”, If the integer is 3 output “INDIA”. If the user enters some other value – output “WRONG ENTRY”.
  • 8. Loop structure (repetition of a set of activities) • In programming, there exists situations when you need to repeat single or a group of statements till some condition is met. Such as - read all files of a directory, send mail to all employees one after another etc. These task in C programming is handled by looping statements. • Looping statement defines a set of repetitive statements. These statements are repeated with same or different parameters for a number of times. Looping statement is also known as iterative or repetitive statement.
  • 9. C supports three looping statements. • for loop • while loop • do...while loop
  • 10. For Loop • For loop is an entry controlled looping statement. It is used to repeat set of statements until some condition is met. • Looping statements whose condition is checked prior to the execution of its body is called as Entry controlled loop. Syntax of Loop for(variable-initialization ; condition ; variable-update) { // Body of for loop }
  • 11.
  • 12. /** * C program to print natural numbers from 1 to 10. */ #include <stdio.h> int main() { /* Declare loop counter variable */ int count; /* Run a loop from 1 to 10 */ for(count=1; count<=10; count++) { /* Print current value of count */ printf("%d ", count); } return 0; }
  • 13. While Loop Start Initializing n=1 n < 10 Stop Print n n = n + 1 True False
  • 14. Do While Loop Start Initializing n=1 n < 10 Stop Print n n = n + 1 True False