0% found this document useful (0 votes)
5 views15 pages

Algorithm & Flowchart

The document discusses the use of loops in algorithms, specifically the WHILE…ENDWHILE and REPEAT…UNTIL structures for repeating tasks based on conditions. It also covers string manipulation techniques and keywords that can be used to perform operations on text. Examples of pseudocode are provided to illustrate the concepts of looping and string manipulation.

Uploaded by

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

Algorithm & Flowchart

The document discusses the use of loops in algorithms, specifically the WHILE…ENDWHILE and REPEAT…UNTIL structures for repeating tasks based on conditions. It also covers string manipulation techniques and keywords that can be used to perform operations on text. Examples of pseudocode are provided to illustrate the concepts of looping and string manipulation.

Uploaded by

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

ALGORITHM & FLOWCHART

Presentation Subtitle
USING LOOPS
We will cover these skills:
• Describe how loops can be used in an
algorithm
• Describe the different ways loops can be
used in a program.
• Describe text manipulating codes in an
algorithm
How loops are
used
• Loops are used in a program to repeat events
a number of times.
• The loop usually ends when after a condition
is no longer met.
• Loops can be used in an algorithm in two
different ways. These are;
• WHILE…… ENDWHILE
• REPEAT…UNTIL
WHILE…ENDWHIL
E
• Note that before we use Loops, we need to
consider the concept of counting the
repetition in the loop.
• This helps the program/algorithm to detect
whether the number of times the condition is
to repeat is up or not.
• The WHILE…ENDWHILE Loop looks like this
WHILE <Condition>
<a statement or list of statements to be carried out>
ENDWHILE
REPEAT…UNTIL
• The syntax for the REPEAT..UNTIL is slightly
different but programmably has the same
execution.
• The REPEAT…UNTIL Loop looks like this
REPEAT
<a statement or list of statements to be carried out>
UNTIL <condition>
WHILE…ENDWHIL
E
• Assuming we want to create a program that
multiplies a user’s number by 10 the number of
times of the user’s number and prints each line
out. The pseudocode for this program should
look like this using the WHILE…ENDWHILE;
count 0
Input number
WHILE count < number
count count +1
write (count, “x 10 =”, count * 10)
ENDWHILE
REPEAT…UNTIL
• This is how the code will look like if we were
using the REPEAT…UNTIL;
count 0
Input number
REPEAT
count count +1
write (count, “x 10 =”, count * 10)
UNTIL count = number
◦ Write an algorithm using WHILE…ENDWHILE
condition, which will input 10 exam marks,
and IF the mark is greater than 40 it will
output “You have passed”. If this was not, Example 2
then it will output “You have failed”.
◦ Re-write the same program using the
REPEAT…UNTIL
TASK
◦ An algorithm needs to continually ask the user to input numbers,
and add them to a total, until the total is more than 100, then add
and output the total.
◦ Create a pseudocode using the WHILE Loop to represent this
process.
String Manipulation
Use Keywords to manipulate
strings/text

Explore some keywords in


string manipulation
String
Manipulation
• We can also manipulate text in a program
to make it interesting.
• String manipulation are keywords used to
perform some skills on text.
• Example, we may want to use only the
first three letters of someone’s first and
last names to create a userID.
String manipulation keywords
Command Description
lenth (string) Returns the length of the string. i.e. the number of
characters in that string including spaces.
char (string, characterNum) Returns the character in the position of a particular
sting.
mid (string, startChar, numChars Returns the character(s) from the startChar and picks
up to the numChars. E.g. mid (“Hello”,1,2) would give
“el”.
upperString(string) Converts any text to uppercase
lower(String) Converts string to lowercase.
First Lesson
Summary
• Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Maecenas porttitor congue
massa. Fusce posuere, magna sed pulvinar
ultricies, purus lectus malesuada libero, sit
amet commodo magna eros quis urna.
• Nunc viverra imperdiet enim. Fusce est.
Vivamus a tellus.
• Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac
turpis egestas.
Lorem Ipsum Dolor
• Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Maecenas porttitor congue
massa.
• Nunc viverra imperdiet enim. Fusce est.
Vivamus a tellus.
• Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac
turpis egestas. Proin pharetra nonummy
pede. Mauris et orci.
THANK YOU!
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Maecenas porttitor congue massa.

You might also like