IF … THEN Statement
It is the most simple form of the control statements which executes a block of statements only if the given expression or condition is true. If the condition is false, then the IF block will skipped and execution continues with the rest of the program.
OR
IF [conditional expression] THEN
[statement]
END IF
Example: 1
CLS INPUT "Enter your marks : "; m IF m >= 35 THEN PRINT "You are passed !!" IF m < 35 THEN PRINT "You are failed .." END
Example: 2
CLS INPUT "Enter a number "; n IF n MOD 2 = 0 THEN PRINT "It is Even Number" IF n MOD 2 = 1 THEN PRINT "It is Odd Number" END
IF … THEN …. ELSE Statement
Example: 1
CLS INPUT "Enter your marks "; m IF m >= 35 THEN PRINT "You are passed !!" ELSE PRINT "You are failed .." END IF END
Example: 2
CLS INPUT "Enter a number "; n IF n MOD 2 = 0 THEN PRINT "Even Number" ELSE PRINT "Odd Number" END IF END
IF … THEN … ELSEIF Statement
Example: 1
CLS INPUT "Enter First Number "; x INPUT "Enter Second Number "; y INPUT "Enter Third Number "; z IF x > y AND x > z THEN PRINT "Greatest number is "; x ELSEIF y > x AND y > z THEN PRINT "Greatest number is "; y ELSE PRINT "Greatest number is "; z END IF END
Example: 2
CLS INPUT "Enter your percentage "; p IF p >= 80 THEN div$ = "Distinction" ELSEIF p >= 60 THEN div$ = "First Divistion" ELSEIF p >= 40 THEN div$ = "Second Division" ELSEIF p >= 35 THEN div$ = "Third Division" ELSE div$ = "Fail" END IF PRINT "Division ::: "; div$ END
SELECT CASE Statement
Select-Case statements work like IF … THEN … ELSEIF statements. The difference is that the Select-Case statement can make the code simpler to read and work with than IF .. THEN … ELSEIF statements.
Example: 1
CLS INPUT "Enter your percentage "; p SELECT CASE p CASE 80 TO 100 div$ = "Distinction" CASE 60 TO 80 div$ = "First Division" CASE 40 TO 60 div$ = "Second Division" CASE 35 TO 40 div$ = "Third Division" CASE ELSE div$ = "Fail" END SELECT PRINT "Division :: "; div$ END
Example: 2
CLS INPUT "Enter First Number "; x INPUT "Enter Second Number "; y PRINT "****** MENU *******" PRINT "1. Addition" PRINT "2. Subtraction" PRINT "3. Multiplication" PRINT "4. Division" INPUT "Enter your choice ! (1/2/3/4) "; ch SELECT CASE ch CASE 1 PRINT "Sum = "; x + y CASE 2 PRINT "Difference = "; x - y CASE 3 PRINT "Product = "; x * y CASE 4 PRINT "Quotient = "; x / y CASE ELSE PRINT "Incorrect choice !!!" END SELECT END
GOTO Statement
It is a only one unconditional branching statement in QBASIC Programming Language. It transfer the flow of program from one statement line to another statement line without checking any condition.
Syntax : GOTO [line number / line label]
Example: 1
CLS n = 1 top: PRINT n; n = n + 1 IF n <= 20 THEN GOTO top END
Example: 2
CLS INPUT "Enter your marks "; m IF m >= 35 THEN GOTO p IF m < 35 THEN GOTO f p: PRINT "You are Passed" END f: PRINT "You are Failed!" END
<< Table of Content >>