0% found this document useful (0 votes)
177 views3 pages

Conditional Statement Handout

This document provides information about conditional statements in pseudocode algorithms. It defines if-then, if-then-else, and if-then-else-if statements. The if-then statement executes code if a condition is true. The if-then-else statement executes one block of code if the condition is true and another if false. The if-then-else-if statement allows checking multiple conditions and executing different code blocks. An example uses these statements to calculate revenue for a stadium based on the stand and number of spectators.

Uploaded by

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

Conditional Statement Handout

This document provides information about conditional statements in pseudocode algorithms. It defines if-then, if-then-else, and if-then-else-if statements. The if-then statement executes code if a condition is true. The if-then-else statement executes one block of code if the condition is true and another if false. The if-then-else-if statement allows checking multiple conditions and executing different code blocks. An example uses these statements to calculate revenue for a stadium based on the stand and number of spectators.

Uploaded by

Ockouri Barnes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LESSON 4

TOPIC: WRITING PSEUDOCODE ALGORITHMS– CONDITIONAL


STATEMENTS

CONDITIONAL STATEMENTS
Explanation
Line 2 – This instruction checks thevalue
When a program is executed, each instruction
stored in the variable Time toseeif it contains
is processed in the sequence listed in the
the value 11.
program, unless specific instructions direct it
to deviate and select other instructions.
Line 3 – The message “Ringthebell”will be
displayed to the user if the result obtainedfrom
THE IF-STATEMENT
Line 2 is true (that is the variableTime
The if-statement is a conditional statement and
contains the value 11). If the result obtained
it allows deviation and selection to take place.
from Line 2 is not true nothingwill be
Read Age (Line1)
displayed.
If Age > 35 then (Line2)
Choosing the correct if-statement to
solve the problem
Line 4 – This instruction terminates theif-then
Else (Line4)
statement.
A number of if-statements are available for use
in programming. Each type of if-statement
(Line5)
Print “Young person” Endif (Line6)
THE IF-THEN-ELSESTATEMENT
will perform differently; so it is very important
When two options are available andaselection
Read Time (Line 1)
to know what results you are typing to
accomplish. must be made, use the if-then-elsestatement. Layout

Endif (Line 4)
THE IF-THEN STATEMENT
If <condition> then
When one option is available and a selection
<one or more instructions whichwill be
may or may not be made, the if-then statement
is used. Layout carried out if the conditionis true>Else
<one or more instructions whichwill be carried
out if the conditionis false>
If <condition> then
Endif
<one or more instructions which will be carried out if the
condition is true>
Endif ageisgreaterthan 35, output “Old person”
Practice Question Input the age of a person. If the otherwiseoutput
The instructions between the if-then and endif
“Young person”.
are executed only if the condition is true. If
the comparison is false, the instructions
Solution
between the if-then and endif are ignored.

Practice Question
Print “Old person”(Line3)
Read the time. If the time is 11:00, output
“Ring the bell”.

Solution

If Time = 11 then (Line 2)


Print “Ring the bell”(Line 3)

20 FPowell jesusaves.fp@gmail.com
Read Stand (Line1)
Read Spectators (Line2)
If Stand = “A” then (Line3)
Else (Line5)
If Stand = “B” then (Line6)
Else (Line8)
If Stand = “C” then (Line9)
Else (Line11)
If Stand = “D” then (Line12)
Endif (Line14)
Endif (Line15)
Endif (Line16)
Endif (Line17)
Print “Stand”, Stand (Line18)
Explanation
Solution
Line 3 – The message “Old person” will be
displayed to the user if the result obtained from Line 2 is true (that is the value stored in the
variable Age is greater than 35).
Revenue = Spectators * 2.00(Line4)

Line 4 – This instruction allows another


instruction to be carried out it the results
Revenue = Spectators * 2.50(Line7)
obtained from Line 2 are false.

Line 5 – The message “Young person” will be


Revenue = Spectators * 4.00(Line10)
displayed to the user if the result obtained from Line 2 is false (that is the value stored in the
variable Age is not greater than 35).
Revenue = Spectators * 5.00(Line13)

THE IF-THEN-ELSE-IF STATEMENT When two or more options are available and a
selection may or may not be made, use the if
then-else-if statement.
Print “Revenue”, Revenue (Line19)
Layout
If <condition> then
<one or more instructions>
Else
If <condition> then
<one or more instructions>
Else
If <condition> then
<one or more instructions>
Endif
Endif
Endif

Note that, for every if-statement, there


must be a corresponding Endif.

Practice Question
A stadium has four stands A, B, C, D. The
admission fee for stand A is 2.00, stand B is 2.50, stand C is 4.00 and stand D is 5.00. Read a stand and
the number of spectators in
the stand. Calculate and print the revenue for
the stand.

21 FPowell jesusaves.fp@gmail.com

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