Computer Studies
What are the different types of conditional statements used in QBASIC programming? Explain.
Answer
There are two conditional statements used in QBASIC. They are as follows:
IF - THEN statement: This statement checks only the 'true' part of the program and comes to an end. It is used to check a condition and then perform any task based on the given condition.
Syntax:
IF THEN
Example:
IF A > 0 THEN PRINT "A IS POSITIVE"
IF - THEN with ELSE statement: This statement performs either of the two specified tasks based on a given condition whether it is 'true' or 'false'.
Syntax:
IF THEN ELSE
Example:
LET A = 5
IF A >= 0 THEN PRINT "A IS POSITIVE" ELSE PRINT "A IS NEGATIVE"
- IF - ELSEIF statement: This statement allows us to check a secondary condition if the first condition is 'False'.
Syntax:
IF THEN
ELSEIF THEN
END IF
Example:
LET A=5
IF A >= 0 THEN PRINT "A IS POSITIVE"
ELSEIF A < 0 THEN PRINT "A IS NEGATIVE"
END IF
Related Questions
Display the output of the following QBASIC program:
CLS
C = 3
D = C*2
START:
PRINT C,D
C = C + 2
IF C <=10 THEN GOTO START:
ENDWhat is a counter? Explain with reference to a program.
An unconditional GOTO sets up an infinite loop. Explain with an example.
Define accumulator. Is it necessary to initialise an accumulator?