0% found this document useful (0 votes)
2K views

If Then Else Pascal

The document discusses the IF-THEN-ELSE conditional structure in programming. It provides an example of an algorithm that accepts a number and prints "Yes" if the number is 5, otherwise it prints "No". It also discusses the key differences between IF-THEN and IF-THEN-ELSE, stating that IF-THEN-ELSE allows for one of two possible outcomes based on a condition, while IF-THEN only allows for a single outcome if the condition is met. Finally, it provides two practice problems to write algorithms using IF-THEN-ELSE.

Uploaded by

api-297910907
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)
2K views

If Then Else Pascal

The document discusses the IF-THEN-ELSE conditional structure in programming. It provides an example of an algorithm that accepts a number and prints "Yes" if the number is 5, otherwise it prints "No". It also discusses the key differences between IF-THEN and IF-THEN-ELSE, stating that IF-THEN-ELSE allows for one of two possible outcomes based on a condition, while IF-THEN only allows for a single outcome if the condition is met. Finally, it provides two practice problems to write algorithms using IF-THEN-ELSE.

Uploaded by

api-297910907
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/ 12

Selection Control

Structures/Selection
Statements/Conditional
Branching
If-THEN-ELSE
Standard
• EK 4.1.2G Every algorithm can be constructed using only sequencing,
selection and iteration

There are three control


structures
Control Structures
• Sequential means each line is executed line by line
• Selection means the program will do something based on a condition
• Iteration means a command is repeated multiple times
Let’s Recap
• In lesson 7 we learnt that programs can be used to perform actions based on a given condition.
• We were introduced to IF-THEN constructs.
• In IF THEN constructs A thing may be done if the condition is true

• For example:
PRINT “Enter the price”
INPUT price
IF price > 60 THEN
dis=10/100*price
Newprice=price-dis
PRINT “The new price is”, Newprice
ENDIF
Recap Cont’d
• Noticed that the 10% discount will only be given if the price is greater
than 60.
Key Points
• In this lesson we will examine IF-THEN- ELSE construct.
• With this construct something may happen if a condition is achieved and another thing
may occur if the same condition is not achieved.
• The format for IF-THEN-ELSE is:

• IF (condition) THEN
action
• ELSE
another action ;
End;
Readln();
END.
Let’s examine the Construct closer.
• Write an algorithm that accepts a number. If the number is 5 print
“Yes” otherwise print “No”.

I P O
num 1) PRINT “Enter a Yes or No
number”
2) INPUT num
3) IF num=5 THEN
4) PRINT “Yes”
5) ELSE
6) PRINT “No”
7) ENDIF
Pseudocode
START
DECLARE num as INTEGER
PRINT “Enter a number”
INPUT num
IF num=5 THEN
PRINT “Yes”
ELSE
PRINT “No”
ENDIF
STOP
Flowchart
START

INPUT num

If Yes
No
num=
5

PRINT “No” PRINT “Yes”

STOP
Pascal
Program Numero;
VAR
Num:integer;
BEGIN
Writeln(‘Program is designed to accept the number 5 and print yes’);
Writeln(‘Please enter a num’);
Read(num);
If (num=5) then
BEGIN
Writeln(‘Yes’)
Else
Writeln(‘No’);
End;
Readln;
END.
Conclusion
• Two types of Selection is IF-THEN and IF-THEN-ELSE
• IF-THEN is used when there is only ONE possible outcome if a
condition met
• IF-THEN-ELSE is used one of two things may occur based on the
condition in a program.
Let’s look at these questions;
1.Write an algorithm in pseudocode,flowchart , pascal program and to
implement the program in Dev Pascal that will accept the age of a
person and display the message “You Can Now Get A Driver’s
Licenses”, If you are over 17 otherwise display “You Are Not Old
Enough To Drive”.

2. Write an algorithm in pseudocode,flowchart , pascal program and to


implement the program in Dev Pascal that will enter a letter of the
alphabet. If the letter is A, E, I, O, or U, display “These Are Vowels”. If
not display “The Letter Is a Consonant”.

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