0% found this document useful (0 votes)
6 views34 pages

Iteration

Uploaded by

huma96692
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)
6 views34 pages

Iteration

Uploaded by

huma96692
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
You are on page 1/ 34

LOOPS

( FOR TO NEXT)
CASE OF OTHERWISE
REVIEW
Agenda
FOR TO NEXT

2
9/3/20XX Presentation Title 3
CASE OF
OTHERWISE

Show Error Message “Math Error” if


they user attempts to divide by Zero

9/3/20XX Presentation Title 4


9/3/20XX Presentation Title 5
6
FOR
Pseudocode
FOR TO NEXT
Repetition/Iterative statements
One or more statements are
repeated till a test condition is met
or when a test condition is TRUE.

FOR Loop – A loop structure that


iterates a set number of times.
The FOR loop is counter-controlled.

8
FOR TO NEXT

Design pseudo-code and flowchart


that prints the word Hello 10 times.

9
Design a program using
loops that takes 5
numbers from the user.
Calculate and display the
total of these numbers.

10
Answer

11
Write pseudocode
that reads 100
numbers and prints
out their average.

12
Answer

13
Write pseudocode
that inputs 50
numbers and counts
the numbers that are
greater than 100.

14
Answer

15
Differences between REPEAT ...
UNTIL and WHILE ... DO ...
ENDWHILE
WHILE.. DO .. ENDWHILE REPEAT.. UNTIL

• In WHILE the criteria is pre- • In REPEAT..UNTIL the criteria is


tested post-tested
• WHILE may never run • REPEAT UNTIL runs at least
• WHILE iterates whilst a once
condition is TRUE • REPEAT UNTIL iterates till a
condition is TRUE

Both REPEAT..UNTIL and WHILE..DO..ENDWHILE loops are called Condition


Controlled Loops

16
WHILE DO
ENDWHILE
Pseudocode
WHILE .. DO …ENDWHILE

18
Design a program that
will read the side
length of a square and
displays its area.
Area = side * side
Repeatedly display an
error message and ask
the user to re-enter the
side length if the side
length is negative.

9/3/20XX Presentation Title 19


Answer

20
Design a program that
takes a mark from the
user and validates that
mark.

Quiz is out of 100.


Count how many times
the user entered
invalid data

21
Answer

22
23
Design a program that
would read numbers
until the user enters 0.
Display the total (sum)
of those numbers

24
Answer

25
Design a program
that takes a mark
from the user and
validates that mark.
Display
whether the student
has passed or failed.
Quiz is out of 100.

26
Answer

27
REPEAT UNTIL
Pseudocode
REPEAT .. UNTIL

29
Design a program
that takes from the
user a radius and
the program outputs
the
circumference
Circumference = 2 * π *
Radius

30
Answer

31
Design a program,
using pseudocode only,
which asks the user to
enter his age and
displays on the screen
You’re a teenager if the
user is younger than
20 years, and
displays on the screen
You’re an adult
otherwise.
Age can’t be less than
1
Age can’t be more than
100
32
Answer

33
RECAP

34

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy