Page 148 - Computer - 6
P. 148
The code and sample output for the example are given below.
Statements in Small Basic
Statements in Small Basic are of three types:
• Assignment • Conditional • Looping
Assignment Statement
The Assignment statement is used to assign a value to a variable. For example, the statement
Class = 6 is an assignment statement that assigns the value 6 to the variable Class.
Conditional Statement
The Conditional statement is used to execute a statement or a group of statements based on
certain conditions. The Conditional statement lets you check a condition and perform specific
functions based on whether the condition is True or False. It is also called the Branching statement.
The common conditional statements used in Small Basic are:
(a) If – Then Statement
The If – Then statement uses three keywords – If, Then, and EndIf. The syntax of this statement is:
If (test condition) Then
<statements to execute if the test condition is true>
EndIf
If the test condition is True, the statements after Then are executed, else the control is transferred to
EndIf that marks the end of the conditional statement.
(b) If – Then – Else Statement
The If – Then – Else statement uses four keywords – If, Then, Else, and EndIf. The syntax of this
statement is:
If (test condition) Then
<statements to execute if the test condition is true>
Else
<statements to execute if the test condition is false>
EndIf
If the test condition is True, the statements after Then are executed and if the test condition is False,
the statements after Else are executed. After execution, the control is transferred to EndIf.
146