Professional Documents
Culture Documents
CLS
If statements are used to check conditions in the program. The structure of the if statement is as
follows:
If <condition> Then
Do something
Do something>
Else
Do something
End If
The Expression Signs (Relational Operators) For If Statements Are:
< Less than <= Less than or equal to > Greater than >= Greater than or equal to
When the condition is met, the code associated with condition will trigger. For example, in a new file
type:
CLS
IF 5 > 2 THEN
END IF
If the greater than changed to a less than, the computer will not output any information because the
condition is not met:
CLS
IF 5 < 2 THEN
END IF
CLS
IF 5 > 10 THEN
ELSE
END IF
The next example will prompt the user to enter two numbers. The program will check for the greatest
number and give a report on its findings.
DIM Num1 AS INTEGER
CLS
ELSE
END IF
Select-Case statements work like If statements. The difference is that the Select-Case statement can
make the code simpler to read and work with than If statements. In some computer languages and
computer systems, the Select-Case statements run faster than the If statements. Creating a Select-Case
statement is simple to do. The next program will prompt the user to select the key A-D and the program
will respond by telling the user what key was entered. We will create a Select-Case statement for the A-
D keys entered.
CLS
KeyPressed = UCASE$(KeyPressed)
PRINT
SELECT CASE KeyPressed
CASE "A"
CASE "B"
CASE "C"
CASE "D"
CASE ELSE
END SELECT
The next program asks for a score then prints the grade assigned to the score.
CLS
CASE IS >= 97
CASE 93 TO 96
CASE 87 TO 89
CASE 83 TO 86
CASE 80 TO 82
CASE 77 TO 79
CASE 73 TO 76
CASE 70 TO 72
CASE 67 TO 69
CASE 63 TO 66
CASE 60 TO 62
CASE ELSE
PRINT "Fail"
END SELECT