Decision Structures Problem Solving Power ICT Presentation
Decision Structures Problem Solving Power ICT Presentation
Structures:
Problem-Solving
Power
Decision structures are fundamental building blocks of code.
They enable programs to respond to different inputs and
make choices based on specific conditions.
Problem-solving:
"process of identifying a problem, or devising possible
solutions and implements the best solutions".
Decision structure:
"Decision structure is a fundamental programming construct that allows a program to execute different
actions based on whether the condition is true or false".
Choosing
Flexibility
Input
IF statement:
Block of if-statement
End
Start
If-else statement:
Input
To provide two outcomes based on
True
If block Else block
End
Being switch
False
True
Case 3 Staement 3
False
True
• To check multiple conditions by placing
One if-statement inside another. Cond
ition False
• Inner If-statement execute only if outer 2
output
Stop
What is Pseudocode?
Pseudocode is a way to describe algorithms and problem-solving logic in simple, plain language. It helps you plan out what your code
should do without worrying about the syntax of a specific programming language.
1- If Statement:
Purpose: Executes a block of code if a specific condition is true. • Example: Check if a number is positive. Pseudocode: Begin
Input number
End If
End
Explanation:
Input number
Else
End If
End
Explanation:
· The program starts by taking input.
Pseudocode:
Begin
Input day
Switch day
Case "Monday":
Case "Wednesday":
Print "Midweek."
Case "Friday":
Default:
End Switch
End
Explanation:
· The program starts by taking input.
Example: Determine if a person can vote and if they are a senior citizen.
Pseudocode: Begin
Input age
Else
End If
Else
End If
End
Explanation:
· The program starts by taking input.
· If both conditions are true, it prints "You can vote. You are a senior citizen."
Communication:
Easy Translation:
Problem-solving with Repetition structure:
• UNDERSTANDING LOOPS
• FLOWCHARTS
• PSEUDO-CODES
Looping through taska:
For Loop
While Loop
2
Executes a block of code as long as a condition is true.
Do-while Loop
3 Executes a block of code at least once, then
checks the condition for further repetitions.
1. For loop
2. While loop
3. Do while loop
For loop:
A for loop is a control flow statement that
allows you to repeat a block of code a specific
number of times or over a sequence (like a
list, range, or other iterable). It's especially
useful when you know in advance how many
times you want to execute a piece of code.
The syntax of a for loop varies depending on
the programming language, but its structure
is generally the same.
Explanation of parts:
1- Initialization: Sets a starting point, often initializing a counter variable.
2- Condition: Checks if the loop should continue. If True, the loop runs; if False, it stops.
3- Update/Increment: Changes the counter variable to eventually make the condition False.
In this loop:
2- Condition: while (count < 5) - The loop will continue as long as count is less than 5.
3-Loop Body: System.out.println ("Count is: " + count); - Prints the current value of count.
4- Increment: count++; - Increases count by 1 on each iteration to eventually make the condition count
< 5 False and stop the loop.
Do While Loop:
A do-while loop is a variation of the while loop
that ensures the code inside the loop is executed
at least once, even if the condition is False from
the start. This is because, in a do-while loop, the
condition is checked after the loop body has been
executed.
Explanation:
1) The code inside the do block executes first.
3) If the condition is true, the loop runs again; if false the loop stops.
Flowchart of Repetition structure:
while loop:
Explanation:
• Initialization:
• A variable (e.g., counter) is initialized with a starting value.
• Condition Check:
• The condition is evaluated. If it's true, the loop body is executed.
• If the condition is false, the loop terminates.
• Loop Body:
• The statements within the loop are executed. These statements typically involve processing data or
performing calculations.
• Do-While Loop:
Another type of repetition structure, the do-while loop, executes the loop body at least once before checking the c
• For Loop:
A for loop is often used when the number of iterations is known in advance.
• Nested Loop:
Loops can be nested within each other to create complex patterns and calculations. By understanding
these concepts and the flowchart representation, you can effectively use repetition structures in your
pseudocode and programming to automate repetitive tasks and solve problems efficiently.
Pseudo-Codes
Example:
(i=1; i<=5; i=i+1) Do
Print I
End For
While Loop Pseudocode
WHILE (condition) DO
statements
END WHILE
Example:
x=1
WHILE (x <= 5) DO
PRINT x
x=x+1
END WHILE
while loop pseudo-code
While (condition) DO
Statements
End while
Example:
X=1
While (x=5) DO
Print x
X=x+1
End while
For Loop Pseudocode
Example:
FOR (i = 1; i <= 5; i = i + 1) DO
PRINT i
END FOR
Do-While Loop Pseudocode
DO
statements
WHILE (condition)
Example:
x=1
DO
PRINT x
x=x+1
WHILE (x <= 5)
Repeat-until loop pseudo-code
Repeat statements
Until (condition)
Example:
X=1
Repeat
Print x
X=x+1
Until (x>5)