0% found this document useful (0 votes)
4 views9 pages

Control Structures in Programming

Uploaded by

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

Control Structures in Programming

Uploaded by

Jhave Javier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Control Structures

in Programming
Control structures are essential tools for organizing and directing
the flow of execution in a program. They enable you to write code
that makes decisions, repeats actions, and handles different
scenarios.
Conditional Statements
Conditional statements allow your program to make decisions
based on certain conditions. They let you determine the path your
code takes based on whether a condition is true or false.

If Else
Execute a block of code Execute a block of code
only if a condition is true. only if the condition is false.

Else If
Allows for multiple checks, executing a block of code if a
specific condition is met.
If-Else Statements
If-else statements are a fundamental building block of decision-making in
programming. They allow you to create conditional execution based on
the outcome of a comparison or evaluation.

Condition
The condition is evaluated.

True
If the condition is true, the code inside the "if" block is executed.

False
If the condition is false, the code inside the "else" block is executed.
Switch Statements
Switch statements provide a more structured and readable way to handle multiple possible outcomes based on a
single value. They are useful when you need to check against a series of specific values.

Case Expression Default

Each case represents a specific value. The expression is evaluated, and If no case matches, the default
the matching case is executed. case is executed.
Ternary Operator
The ternary operator provides a compact syntax for writing
conditional expressions. It offers a concise way to assign a value
based on a condition, eliminating the need for lengthy if-else
statements.

True Value 3 False Value


1 Condition 2
The condition is evaluated. If the condition is true, If the condition is false, the false value is

the true value is returned.

returned.
Loops
Loops are essential for repeating a block of code multiple times. They automate
repetitive tasks and save you from writing the same code repeatedly.

1 Initialization
Set the initial values for loop control variables.

2 Condition
The loop continues to execute as long as the condition is true.

3 Iteration
The loop body executes once for each iteration.

4 Update
Update the loop control variables to prepare for the next iteration.
For Loops
For loops are designed for situations where you know in advance
how many times you want to repeat a process. They simplify the
process of looping a specific number of times.

Initialization The loop counter is set to its


initial value.

Condition The condition is evaluated


before each iteration.

Update The loop counter is updated


after each iteration.
While Loops
While loops are useful when you want to repeat a block of code until a certain condition is met. They provide
flexibility in controlling the loop's execution based on the condition's outcome.

Condition Iteration Repeat


The condition is checked before If the condition is true, the loop The condition is checked again, and
each iteration. body is executed. the process repeats.
Do-While Loops
Do-while loops ensure that the loop body is executed at least once,
even if the condition is initially false. This is useful when you need
to perform an action at least once and then evaluate the condition
for subsequent iterations.

1 Do 2 While
The loop body is The condition is checked
executed at least once. after each iteration.

3 Repeat
If the condition is true, the loop body is executed again.

You might also like