Page 88 - TCS ICT Book 8
P. 88
The City School 2021-2022
If...Then...Else Statement
An other variant of the conditional statement is the If…Then…Else statement. This
allows you to define instructions to be executed if the condition is false. For example,
let’s say we want the previous program to display a relevant message to the user not
only when the correct number is found but also when a wrong number is inserted.
Add the else block in previous your code to understand how If...Then...Else statements
work.
If...Then...ElseIf Statement
If there are more than two choices to display, using the If...Then...Else statement is not
enough. To provide more choices, we can use the If...Then...ElseIf statement. In the
following example, we have created a program that translates a student’s score to the
corresponding grade.
Follow the steps below to create the program using If…Then…Elself statement:
1. Create a new form with three labels,
one text box and a button.
2. Edit the text for the first label to Enter
Your Score.
3. Edit the button text to Show Grade.
4. Edit the text of the second label to
Your Grade:
5. Place the third label adjacent to the
second label and we will use this label
88

