SlideShare a Scribd company logo
Jan 2023
FUNDAMENTALS OF COMPUTER
PROGRAMMING
Chere L. (M. Tech)
Lecturer, SWEG, AASTU
Using C++
Jan 2023
PROGRAM FLOW CONTROLS
(Selection Statements)
Outline
▪ Introduction to flow control
▪ Branching flow controls
✓ One-way selection
✓ Two-way selection
✓ Multiple selections
✓ switch statement
CHAPTER FOUR
Jan 2023
PROGRAM FLOW CONTROLS
(Loop Statements)
Outline
▪ Introduction to iterative flow control
▪ Iterative/looping flow controls Stmts
✓ for loop
✓ while loop
✓ do . . . while loop
▪ Jumping statements
✓ break, continue, goto
▪ Program termination statements
✓ return, exit, abort
CHAPTER FOUR
Jan 2023
Objectives
At the end of this section, you able to
▪ Identify and use selection flow controls and iterative flow controls.
▪ Form and evaluate Boolean expressions
▪ Examine the relational and logical operators
▪ Determine the use case of the various selection, looping, jumping,
and program termination statements
▪ Design and develop a program using selection and loop statements
and the other flow control statements.
Jan 2023
4.1 Introduction to Flow Control
Jan 2023
What is flow control?
▪ It refers to the order in which a program statements (instructions) are
executed (performs actions).
▪ The term reflects the fact that the currently executing statement has
control of the CPU and is handed over (flow) to another statement when
its execution is completed.
Jan 2023
Cont’d
The natural flow control of program
▪ Typically, the flow control in a program is
sequential, which is the most common and
straightforward.
▪ However, usually a program execution is not
limited to a sequential
Jan 2023
Cont’d
Can the programmer
alter the normal
order of program
execution?
▪ Yes, programmers can control the order of
instruction execution
▪ Accordingly, most programming language
including C++ provides control structures that
serve to specify what has to be done by our
program, when and under which circumstances.
Jan 2023
The Basic Program Flow Controls
▪ Generally there are three basic program flow controls
Execution of instructions
sequentially one after
another
allow alternative actions
based upon conditions that
are evaluated at run time
allows to execute a
statement or group of
statements multiple times
Jan 2023
Types of Selection Statements
✓ One-way selection --- if Stmts
✓ Two-way selection --- if . . . else Stmts
✓ Multiple selection
➢ if . . . else if Stmts
➢ switch Stmts
➢ nested selection Stmts
Types of Looping Statements
✓ while loop
✓ for loop
✓ do...while loop
✓ Nested looping
Also group as
➢ Pre-test loops Vs. Post-test loops
➢ Count-controlled Vs. Event-controlled
Jan 2023
Selection Statements
Jan 2023
Identify the type of selection statements and write their syntax
1
2
if (expression) {
statement (s);
}
next statement(s);
▪ if the condition (Boolean expression)
is TRUE (evaluated to 1), then
statement(s) or the block that follows
the selection is executed and then the
next statement(s) gets executed.
▪ Otherwise nothing will be executed and
execution continues with the next
statement in the program.
Expression/condition
✓ It is a Boolean expression
✓ A condition that must be evaluated to
be true/false
✓ two or more relational expressions can
be combined with logical operators
if (expression){
statement1 / block1
}else{
statement2 / block2;
}
next statement(s);
Jan 2023
Cont’d
3
if (expression1){
statement1 / block1
}
else if (expression2){
statement2 / block2;
}
. . . . .
else {
statement-N / block-N;
}
next statement(s);
Jan 2023
Cont. . .
4
Jan 2023
Nested Selection Stmts
5
if (expression1){
if (expression1.1){
statement1.1 / block1.1;
}
statement1.2 / block1.2 //optional
}
else {
if (expression2){
statement2 / block2;
}
else if (expression3){
statement3 / block3;
}
else
statement4 / block4
}
next statement(s);
Jan 2023
Looping Statements
Jan 2023
Part of looping statements
▪ Initialization Expression(s)
✓ Initialize(s) the loop
✓ Variables at the beginning of the loop.
▪ Test Expression
✓ Decides whether the loop will be executed (if the test expression is true) or
not (if the test expression is false).
▪ Update Expression(s)
✓ Update(s) the values of loop variables after every iteration of the loop.
▪ The Body-of-the-Loop
✓ Contains statements to be executed repeatedly.
Jan 2023
Identify the type of looping statements and write their syntax
6
while (repetition condition) {
statement (s);
}
next statement(s);
Jan 2023
Cont’d
7
statement
true
condition
evaluated
false
increment
initialization
for ( initialization ; condition ; increment )
{
statement;
}
Theinitialization is
executed once before
the loopbegins
✓ It is similar to the while loop
condition part
✓ The statement is executed until
the conditionbecomes false
The incrementportionis
executed at
the end of eachiteration
Jan 2023
Cont’d
8
do {
statement (s);
} while (repetition condition)
next statement(s);
Jan 2023
Nested Loops
9
Jan 2023
Reading Resources/Materials
eBooks – selection statements
▪ Chapter 5 & 6: Diane Zak; An Introduction to Programming with C++ [8th Edition],
2016 Cengage Learning
▪ Chapter 4: Gary J. Bronson; C++ For Engineers and Scientists [3rd edition],
Course Technology, Cengage Learning, 2010
▪ Chapter 2 (section 2.4): Walter Savitch; Problem Solving With C++ [10th edition],
University of California, San Diego, 2018
▪ Chapter 4: P. Deitel , H. Deitel; C++ how to program, [10th, Global Edition] (2017)
Jan 2023
Reading Resources/Materials
eBooks – loop statements
▪ Chapter 7 & 8: Diane Zak; An Introduction to Programming with C++ [8th Edition],
2016 Cengage Learning
▪ Chapter 5: Gary J. Bronson; C++ For Engineers and Scientists [3rd edition],
Course Technology, Cengage Learning, 2010
▪ Chapter 2 (section 2.4): Walter Savitch; Problem Solving With C++ [10th edition],
University of California, San Diego, 2018
▪ Chapter 4 & 5: P. Deitel , H. Deitel; C++ how to program, [10th, Global Ed.] (2017)
Jan 2023
Reading Resources/Materials
Online Materials
▪ https://www.w3schools.com/cpp/default.asp
▪ https://www.javatpoint.com/cpp-tutorial
▪ https://www.programiz.com/cpp-programming
▪ https://www.hackerrank.com/domains/cpp
▪ https://cplusplus.com/doc/tutorial/
Jan 2023
Thank You
For Your Attention!!

More Related Content

Similar to Fundamentals of Computer Programming Summary of Flow Controls (20)

PPT
3. control statements
amar kakde
 
PPTX
Chapter 3
enidegmossu
 
PPT
2. Control structures with for while and do while.ppt
ManojKhadilkar1
 
PPT
control-statements, control-statements, control statement
crrpavankumar
 
PPT
control-statements detailed presentation
gayathripcs
 
PPT
control-statements....ppt - definition
Papitha7
 
PPT
Control Statements, Array, Pointer, Structures
indra Kishor
 
PPTX
Bsc cs pic u-3 handling input output and control statements
Rai University
 
PPTX
Diploma ii cfpc u-3 handling input output and control statements
Rai University
 
PPT
Control structure
Samsil Arefin
 
PPT
Flow of control c++
Arpit Meena
 
PPTX
Cse lecture-7-c loop
FarshidKhan
 
PPTX
handling input output and control statements
Rai University
 
PPTX
CONTROL STMTS.pptx
JavvajiVenkat
 
PPTX
Control structures
ElakkiyaS11
 
PPTX
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
PPTX
Btech i pic u-3 handling input output and control statements
Rai University
 
PPTX
C++ decision making
Zohaib Ahmed
 
PPTX
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
PallaviGholap4
 
PPTX
5.pptx fundamental programing one branch
ssuserdde43b
 
3. control statements
amar kakde
 
Chapter 3
enidegmossu
 
2. Control structures with for while and do while.ppt
ManojKhadilkar1
 
control-statements, control-statements, control statement
crrpavankumar
 
control-statements detailed presentation
gayathripcs
 
control-statements....ppt - definition
Papitha7
 
Control Statements, Array, Pointer, Structures
indra Kishor
 
Bsc cs pic u-3 handling input output and control statements
Rai University
 
Diploma ii cfpc u-3 handling input output and control statements
Rai University
 
Control structure
Samsil Arefin
 
Flow of control c++
Arpit Meena
 
Cse lecture-7-c loop
FarshidKhan
 
handling input output and control statements
Rai University
 
CONTROL STMTS.pptx
JavvajiVenkat
 
Control structures
ElakkiyaS11
 
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Btech i pic u-3 handling input output and control statements
Rai University
 
C++ decision making
Zohaib Ahmed
 
C PROGRAMMING-CONTROL STATEMENT (IF-ELSE, SWITCH)
PallaviGholap4
 
5.pptx fundamental programing one branch
ssuserdde43b
 

More from ChereLemma2 (9)

PPTX
Ch5 Project Scope Management xxxxxxxxx.pptx
ChereLemma2
 
PPTX
Lecture - Project Scope Management slide
ChereLemma2
 
PPTX
Ch-3(b) - Variables and Data types in C++.pptx
ChereLemma2
 
PPTX
Chapter 6 - Modular Programming- in C++.pptx
ChereLemma2
 
PPTX
User Defined Datatypes in C++ (Union, enum, class)
ChereLemma2
 
PDF
Fundamentals of Computer Programming - Flow of Control I
ChereLemma2
 
PPTX
File Management and manipulation in C++ Programming
ChereLemma2
 
PDF
Basic Concepts of Programming - Practical Exercises
ChereLemma2
 
PPTX
Fundamentals of Computer Programming in C++ Key Concepts
ChereLemma2
 
Ch5 Project Scope Management xxxxxxxxx.pptx
ChereLemma2
 
Lecture - Project Scope Management slide
ChereLemma2
 
Ch-3(b) - Variables and Data types in C++.pptx
ChereLemma2
 
Chapter 6 - Modular Programming- in C++.pptx
ChereLemma2
 
User Defined Datatypes in C++ (Union, enum, class)
ChereLemma2
 
Fundamentals of Computer Programming - Flow of Control I
ChereLemma2
 
File Management and manipulation in C++ Programming
ChereLemma2
 
Basic Concepts of Programming - Practical Exercises
ChereLemma2
 
Fundamentals of Computer Programming in C++ Key Concepts
ChereLemma2
 
Ad

Recently uploaded (20)

PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Horarios de distribución de agua en julio
pegazohn1978
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Controller Request and Response in Odoo18
Celine George
 
Ad

Fundamentals of Computer Programming Summary of Flow Controls

  • 1. Jan 2023 FUNDAMENTALS OF COMPUTER PROGRAMMING Chere L. (M. Tech) Lecturer, SWEG, AASTU Using C++
  • 2. Jan 2023 PROGRAM FLOW CONTROLS (Selection Statements) Outline ▪ Introduction to flow control ▪ Branching flow controls ✓ One-way selection ✓ Two-way selection ✓ Multiple selections ✓ switch statement CHAPTER FOUR
  • 3. Jan 2023 PROGRAM FLOW CONTROLS (Loop Statements) Outline ▪ Introduction to iterative flow control ▪ Iterative/looping flow controls Stmts ✓ for loop ✓ while loop ✓ do . . . while loop ▪ Jumping statements ✓ break, continue, goto ▪ Program termination statements ✓ return, exit, abort CHAPTER FOUR
  • 4. Jan 2023 Objectives At the end of this section, you able to ▪ Identify and use selection flow controls and iterative flow controls. ▪ Form and evaluate Boolean expressions ▪ Examine the relational and logical operators ▪ Determine the use case of the various selection, looping, jumping, and program termination statements ▪ Design and develop a program using selection and loop statements and the other flow control statements.
  • 5. Jan 2023 4.1 Introduction to Flow Control
  • 6. Jan 2023 What is flow control? ▪ It refers to the order in which a program statements (instructions) are executed (performs actions). ▪ The term reflects the fact that the currently executing statement has control of the CPU and is handed over (flow) to another statement when its execution is completed.
  • 7. Jan 2023 Cont’d The natural flow control of program ▪ Typically, the flow control in a program is sequential, which is the most common and straightforward. ▪ However, usually a program execution is not limited to a sequential
  • 8. Jan 2023 Cont’d Can the programmer alter the normal order of program execution? ▪ Yes, programmers can control the order of instruction execution ▪ Accordingly, most programming language including C++ provides control structures that serve to specify what has to be done by our program, when and under which circumstances.
  • 9. Jan 2023 The Basic Program Flow Controls ▪ Generally there are three basic program flow controls Execution of instructions sequentially one after another allow alternative actions based upon conditions that are evaluated at run time allows to execute a statement or group of statements multiple times
  • 10. Jan 2023 Types of Selection Statements ✓ One-way selection --- if Stmts ✓ Two-way selection --- if . . . else Stmts ✓ Multiple selection ➢ if . . . else if Stmts ➢ switch Stmts ➢ nested selection Stmts Types of Looping Statements ✓ while loop ✓ for loop ✓ do...while loop ✓ Nested looping Also group as ➢ Pre-test loops Vs. Post-test loops ➢ Count-controlled Vs. Event-controlled
  • 12. Jan 2023 Identify the type of selection statements and write their syntax 1 2 if (expression) { statement (s); } next statement(s); ▪ if the condition (Boolean expression) is TRUE (evaluated to 1), then statement(s) or the block that follows the selection is executed and then the next statement(s) gets executed. ▪ Otherwise nothing will be executed and execution continues with the next statement in the program. Expression/condition ✓ It is a Boolean expression ✓ A condition that must be evaluated to be true/false ✓ two or more relational expressions can be combined with logical operators if (expression){ statement1 / block1 }else{ statement2 / block2; } next statement(s);
  • 13. Jan 2023 Cont’d 3 if (expression1){ statement1 / block1 } else if (expression2){ statement2 / block2; } . . . . . else { statement-N / block-N; } next statement(s);
  • 15. Jan 2023 Nested Selection Stmts 5 if (expression1){ if (expression1.1){ statement1.1 / block1.1; } statement1.2 / block1.2 //optional } else { if (expression2){ statement2 / block2; } else if (expression3){ statement3 / block3; } else statement4 / block4 } next statement(s);
  • 17. Jan 2023 Part of looping statements ▪ Initialization Expression(s) ✓ Initialize(s) the loop ✓ Variables at the beginning of the loop. ▪ Test Expression ✓ Decides whether the loop will be executed (if the test expression is true) or not (if the test expression is false). ▪ Update Expression(s) ✓ Update(s) the values of loop variables after every iteration of the loop. ▪ The Body-of-the-Loop ✓ Contains statements to be executed repeatedly.
  • 18. Jan 2023 Identify the type of looping statements and write their syntax 6 while (repetition condition) { statement (s); } next statement(s);
  • 19. Jan 2023 Cont’d 7 statement true condition evaluated false increment initialization for ( initialization ; condition ; increment ) { statement; } Theinitialization is executed once before the loopbegins ✓ It is similar to the while loop condition part ✓ The statement is executed until the conditionbecomes false The incrementportionis executed at the end of eachiteration
  • 20. Jan 2023 Cont’d 8 do { statement (s); } while (repetition condition) next statement(s);
  • 22. Jan 2023 Reading Resources/Materials eBooks – selection statements ▪ Chapter 5 & 6: Diane Zak; An Introduction to Programming with C++ [8th Edition], 2016 Cengage Learning ▪ Chapter 4: Gary J. Bronson; C++ For Engineers and Scientists [3rd edition], Course Technology, Cengage Learning, 2010 ▪ Chapter 2 (section 2.4): Walter Savitch; Problem Solving With C++ [10th edition], University of California, San Diego, 2018 ▪ Chapter 4: P. Deitel , H. Deitel; C++ how to program, [10th, Global Edition] (2017)
  • 23. Jan 2023 Reading Resources/Materials eBooks – loop statements ▪ Chapter 7 & 8: Diane Zak; An Introduction to Programming with C++ [8th Edition], 2016 Cengage Learning ▪ Chapter 5: Gary J. Bronson; C++ For Engineers and Scientists [3rd edition], Course Technology, Cengage Learning, 2010 ▪ Chapter 2 (section 2.4): Walter Savitch; Problem Solving With C++ [10th edition], University of California, San Diego, 2018 ▪ Chapter 4 & 5: P. Deitel , H. Deitel; C++ how to program, [10th, Global Ed.] (2017)
  • 24. Jan 2023 Reading Resources/Materials Online Materials ▪ https://www.w3schools.com/cpp/default.asp ▪ https://www.javatpoint.com/cpp-tutorial ▪ https://www.programiz.com/cpp-programming ▪ https://www.hackerrank.com/domains/cpp ▪ https://cplusplus.com/doc/tutorial/
  • 25. Jan 2023 Thank You For Your Attention!!