Program
Control
Structure s
PRESENTED BY: GROUP 1
Control
Structures
Are ways to specify flows control
in programs. It basically
analyzes and choose which
direction a program flows.
3 Basic types of flow
• Sequential
control
Logic 02
• Selection Logic
• Iteration Logic
CONTROL
STRUCTURES
SIMPLE
CONTROL FUNCTIONS
STRUCTURES
IF AND ELSE DO
CONDITIO STATEMENT WHILE
LOOPS
NAL
NESTED IF
ELSE
FOR WHILE
Sequence
-the line-by-line execution by
which statements are executed
sequentially, in the same order
in which they appear in the
program.
#include <iostream>
int main() {
std::cout << "First statement\n";
std::cout << "Second statement\n";
std::cout << "Third statement\n";
return 0;
}
Selection
-used for decisions and
branching, where you choose
between two or more alternative
paths. (Ex. If, If-else and switch
statement).
Iteration
-also known as looping, where a
specific block of code is run until
a certain condition is met. (Ex.
for, while and do-while loops).
Function
Functions are used to perform
certain actions, and they are
important for reusing code:
Define the code once, and use it
many times.
Conditional
If Else Nested If
Statement statement statement
If statement
-the if statement is a fundamental control
flow structure that allows your program to
make decisions.
It executes a block of code only if a
specific condition is true.
Syntax
if (condition) {
// Code to be executed if the condition is true
} else {
// Code to be executed if the condition is false
(optional)
}
Example
#include <iostream> // checks if the number is positive
using namespace std; if (number > 0) {
cout << "You entered a positive
int main() { number << endl;
}
int number;
cout << "This statement is alwa
cout << "Enter an integer: ";
cin >> number; return 0;
Output
Output
Else
-used to provide an alternative block of
statement
code that executes when the condition
in the preceding if statement evaluates
to false. It is typically used to handle
cases where the if condition is not met.
Syntax
if (condition) {
// Code that executes if the condition is true
} else {
// Code that executes if the condition is false
}
Example
#include <iostream>
} else {
int main() { std::cout << "You are not
int age = 17; vote." << std::endl;
}
if (age >= 18) {
std::cout << "You are eligible to return 0;
vote." << std::endl; }
Output
Nested If statement
-is an if statement that is placed inside
another if statement. This allows you to
check for multiple conditions and execute
different blocks of code depending on the
outcome of each condition.
how nested if statements
work
1. Outer if statement: The outer if statement checks the
first condition. If the condition is true, the code blocks
inside the outer if statement is executed.
2. Inner if statement: Inside the outer if statement, there
can be one or more inner if statements. These inner if
statements check additional conditions.
how nested if statements
work
3. Execution: If an inner if statement's condition
is true, the code block inside that inner if
statement is executed.
#include <iostream> Example
int main() {
int num; } else {
std::cout << num << " is a positive number
std::cout << "Enter a number: "; greater than or equal to 100." << std::endl;
std::cin >> num; }
} else {
std::cout << num << " is not a positive number."
if (num > 0) { // Outer if statement
<< std::endl;
if (num < 100) { // Inner if statement }
std::cout << num << " is a positive return 0;
number less than 100." << std::endl; }
Thank You