Chapter 7: Statements in QBasic: ✅ EVALUATE
Tick (✔) the correct answer.
- The string variables are ended with a ____ sign.
- !
- ✔ @
- $
- Which of the following is NOT a conditional statement?
- IF…THEN
- ✔ WHILE…WEND
- SELECT…CASE
- The keyword ______ is added to the IF…THEN…ELSE statement when there are many conditions.
- ✔ ELSEIF
- STEP
- LOOP
- Which statement can be used instead of nested IF…THEN…ELSE?
- WHILE…WEND
- ✔ SELECT…CASE
- FOR…NEXT
- When there is a need to repeat commands in a program, ______ statements are used.
- Conditional
- Branching
- ✔ Looping
✅ Fill in the blanks.
- String variables cannot be used in mathematical operations.
- Conditional statements are also known as branching statements.
- The END IF statement is used to end a multiple-line IF block.
- When there is a need to repeat the execution a specific number of times, FOR…NEXT loop is used.
- When we use one or more FOR…NEXT loops inside another, it is termed as a nested loop.
✅ Write ‘T’ for True and ‘F’ for False statements.
- 1974 is an example of string variable — F
- Numeric variables must always begin with an alphabet — T
- The REM statement is used to clear the output screen — F
- DO..... WHILE is totally the same as WHILE WEND loop.— F
- IF THEN ELSE statement is an extended version of IF THEN statement. — T
✅ Answer the following questions.
1. Write the syntax of IF…THEN…ELSE statement.
IF condition THEN
statements
ELSE
statements
END IF
2. What is the use of the STEP keyword in the FOR…NEXT loop?
The STEP keyword is used to change the jump value in the loop. It tells the loop how much to increase or decrease the counter each time.
FOR I = 1 TO 10 STEP 2
PRINT I
NEXT I
' Increases I by 2 (1, 3, 5…)
3. Identify the errors in the following programs and correct them.
(a) Incorrect Program
CLS
PRINT "Enter a number from 0 to 9.
INPUT N
FOR IN TO 9 STEP 2
PRINTI
END
Corrected Program
CLS
PRINT "Enter a number from 0 to 9."
INPUT N
FOR I = N TO 9 STEP 2
PRINT I
NEXT I
END
(b) Incorrect Program
CLS
PRINT I = 1
WHILE I <= 100
LET 1: 1=1*2
WEND
END
Corrected Program
CLS
I = 1
WHILE I <= 100
I = I * 2
WEND
END
4. Write a short note on WHILE…WEND loop.
The WHILE…WEND loop is used when we want to repeat a set of instructions as long as a condition is true. The loop stops when the condition becomes false.
WHILE condition
statements
WEND
5. Difference between DO…LOOP WHILE and DO UNTIL…LOOP.
DO…LOOP WHILE
Repeats the loop while the condition is true. When the condition becomes false, the loop ends.
DO
PRINT A
A = A + 1
LOOP WHILE A <= 5
DO UNTIL…LOOP
Repeats the loop until the condition becomes true. The loop continues as long as the condition is false.
DO
PRINT A
A = A + 1
LOOP UNTIL A > 5
✅ Define the following terms.
1. Variable
A variable is a name used to store data in the computer’s memory. It can hold numeric or string values.
Examples: A, X1, TOTAL, B$
2. Branching Statement
Branching statements allow a program to take different execution paths based on conditions.
Examples: IF…THEN, IF…THEN…ELSE, SELECT…CASE
3. END IF Statement
The END IF statement is used to close a multi-line IF block in QBasic. It marks the end of the decision-making structure.
4. Looping
Looping is the process of repeating a set of instructions until a specific condition is met. It reduces the need to write repeated code.
Examples: FOR…NEXT, WHILE…WEND, DO…LOOP
5. STEP Keyword
The STEP keyword is used in the FOR…NEXT loop to change the increment or decrement value of the counter. It controls how much the loop variable increases or decreases after each iteration.
Example: FOR I = 1 TO 10 STEP 2

0 Comments