Statements in Qbasic

Codynn
3 Min Read

A statement is a collection of instructions written in QBASIC using keywords and commands. There are three types of statements in basic:

    IF Statement

The IF statement always asks a question (usually about the number in a variable.) If the answer is TRUE the true branch is executed. If the answer is FALSE the true branch is skipped. In both cases, execution continues with the statement after the END IF. Example:

CLS
IF 5>2 THEN
PRINT “5 is greater than 2”
END IF

 IF-ELSE Statement

The if-else statement is a conditional statement that runs a block of code if a certain condition is met. If the Boolean expression is false, the if statement might be followed by an optional else statement.

Example:

CLS
INPUT "Enter any number “; N
IF N MOD 2 =0 THEN
PRINT "The number is EVEN ";
ELSE
PRINT "The number is ODD ";
END IF
END

IF ELSE IF:

Statement:f else if statement is a conditional control chain of statement in Qbasic, here first the program check the first expression of the program and if the requirement is false, it sends you back to the if-else condition. In simple words, it will simply check the first expression and if the first expression is an error it moves to the second. And finally, need to end the statement using end if.

CLS
INPUT "ENTER ANY THREE NUMBERS "; A, B, C
IF A < B AND A < C THEN
PRINT A; "IS SMALLEST "
ELSEIF B < A AND B < C THEN
PRINT B; "IS SMALLEST "
ELSE
PRINT C; "IS SMALLEST "
END IF
END

SELECT CASE Statement

The test expression is evaluated by SELECT CASE, which then performs the first matching CASE or CASE ELSE block and leaves. SELECT EVERY CASE allows all matching CASE blocks or the CASE ELSE block to be executed in order from top to bottom.

Syntax:

SELECT CASE expression

case 1stexpression

statement A

Case 2nd expression

statement B

Case Else

default expression

REM to check the entered letter is vowel or consonant.
CLS
Input” Enter a letter”; letter
SELECT Case letter
       CASE a 
			   PRINT “IT is vowel”
			CASE e
				PRINT “it is vowel”
			CASE i
				PRINT “it is vowel”
       CASE o
         PRINT” it is vowel”
        CASE u
			   PRINT” it is vowel”
       CASE A
			  PRINT “IT is vowel”
			CASE E
				PRINT “it is vowel”
			CASE I
				PRINT “it is vowel”
       CASE O
        PRINT” it is vowel”
       CASE U
			  PRINT” it is vowel”
       CASE ELSE
				PRINT “Consonant”
		    END SELECT   
	      END

Share This Article
1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *