0% found this document useful (0 votes)
5K views10 pages

If Then Else

1) The document discusses control structures in algorithms and programs, specifically selection structures like IF-THEN and IF-THEN-ELSE. 2) IF-THEN-ELSE allows a program to do one thing if a condition is true, and another if the condition is false. 3) An example is provided of an algorithm that accepts a number as input, and prints "Yes" if the number is 5, or "No" if the number is not 5.

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)
5K views10 pages

If Then Else

1) The document discusses control structures in algorithms and programs, specifically selection structures like IF-THEN and IF-THEN-ELSE. 2) IF-THEN-ELSE allows a program to do one thing if a condition is true, and another if the condition is false. 3) An example is provided of an algorithm that accepts a number as input, and prints "Yes" if the number is 5, or "No" if the number is not 5.

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/ 10

Algorithms & Programs

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
• Do something
• ELSE
• Do another something
• ENDIF
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
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.

You might also like