Font size
WorksheetsGr 7 - QBASIC LOOPS
Total questions: 36
Worksheet time: 35mins
Identify the counter variable in the given program
FOR i = 1 TO 4
PRINT “computer”
NEXT
(a)
Identify the Initial value in the given program
FOR i = 1 TO 11
PRINT “5”
NEXT i
(a)
1. A repeated execution of statements for a fixed number of times is known as________
Loop
Repeat
Again
execution
2. The number of times the for next loop gets executed is based on the difference between ______________ value.
n value
start value and end value
maximum value
x and y value
3. To execute a group of statements for a specific number of times ___________ loop is used.
for next
while
do while
do until
What will be the output of the following code?
FOR i = 1 TO 5
PRINT i
NEXT
1 2 3 4 5 6
1 2 3 4 5
5 4 3 2 1
1 2 3 4
i = 5
DO UNTIL i > 7
PRINT i;
i = i + 1
LOOP
5 6 7
5 6
5 6 7 8
5
What will be the output of the following code?
FOR i = 1 TO 6 STEP 2
PRINT i;
NEXT
1 3 5
1 2 3 4 5 6
2 4 6
1
What will be the output of the following code?
FOR i = 16 TO 61 STEP -2
PRINT i;
NEXT
10 8 6
10 8
10 9 8 7 6
No output
i = 10
DO WHILE i >= 7
PRINT i;
i = i - 1
LOOP
10 9 8 7
10 9 8
10
No output
What will happen if the following code is executed?
FOR i = 1 TO 5
PRINT i;
NEXT
The loop will execute and print numbers from 1 to 5.
There will be a syntax error because of ; symbol
The code will run but skip one iteration.
The program will not execute due to missing snack and drink
What is the reason for the output being infinite in the following code?
i = 1
DO WHILE i > 0
PRINT i;
i = i + 1
LOOP
There is no termination condition for the loop
The value of i is increasing indefinitely
All answers are correct
The condition is always true
How can you avoid an infinite loop in this code?
Add a decrement statement for i
Change the condition to DO WHILE i < 5
Use a FOR loop instead of a DO WHILE loop
All wrong
How does the use of STEP in the following code affect execution?
FOR i = 10 TO 1 STEP -2
PRINT i;
NEXT
The loop decrements i by 2 after each iteration
The loop increments i by 2 after each iteration
The loop terminates immediately because of a negative STEP
All wrong
Why does the following code result in no output?
FOR i = 1 TO 0 STEP 1
PRINT i;
NEXT
The condition 1 TO 0 makes the loop invalid
The STEP 1 ensures no iterations occur
The loop starts with an invalid range
All wrong
What happens if the LOOP statement is omitted (Deleted) from this code?
i = 1
DO WHILE i <= 3
PRINT i;
i = i + 1
LOOP
The loop will run indefinitely
The program will throw an error
The program will execute only once
All wrong
What is a FOR...NEXT loop in QBasic?
A loop that runs until a condition is false
A loop with a fixed number of iterations
A loop that runs indefinitely
A loop that executes at least once regardless of condition
Which statement best defines a DO WHILE loop in QBasic?
A loop that runs a fixed number of times
A loop that repeats as long as the condition is true
A loop that executes before the condition
A loop that increments a variable automatically
What is the purpose of a DO UNTIL loop?
To execute a set of statements until the condition becomes true
To execute statements until a variable reaches a specific value
To execute a loop indefinitely
To count iterations automatically
What is the difference between DO WHILE and DO UNTIL loops?
DO UNTIL runs as long as the condition is true, while DO WHILE runs until the condition becomes true
DO WHILE runs as long as the condition is true, while DO UNTIL runs until the condition becomes true
DO WHILE only works with numeric values, while DO UNTIL does not
There is no difference between them
What does the STEP keyword in a FOR...NEXT loop define?
It is used for decoration
The condition for exiting the loop
The increment (or decrement) value for each iteration
The starting value of the loop variable
FOR i = 1 TO 3
PRINT i
NEXT
1 2 3
1 2 3 4
0 1 2 3
3 2 1
x = 10
DO WHILE x > 5
PRINT x
x = x - 2
LOOP
10 8 6
10 8
10 8 6 4
Infinite loop
Which of the following best describes the behavior of this code?
x = 5
DO UNTIL x = 0
PRINT x
x = x - 2
LOOP
Prints numbers 5, 3, 1
Prints numbers 5, 3, 1, -1
Infinite loop
Does not print anything
rue or False: The following code does not work
FOR i = 1 TO 10 STEP -1
PRINT i
NEXT
True
False
Analyze the behavior of this code and select all correct statements.
x = 5
DO WHILE x <= 15
PRINT x
x = x + 3
LOOP
Prints numbers starting from 5 to 15, incrementing by 3
Last number printed is 17
The loop runs 5 times
The loop runs 4 times
True or False: The following code outputs only even numbers between 2 and 10.
FOR i = 2 TO 10 STEP 2
PRINT i
NEXT i
True
False
Which of the following will create an infinite loop?
FOR i = 1 TO 5
PRINT i
NEXT i
x=1
DO WHILE x > 0
PRINT x
LOOP
x=0
DO UNTIL x < 0
PRINT x
LOOP
All wrong
Line 1
Line 2
Line 3
Line 4
5. ____________________ types of Do loops are available in QBasic.
2
1
3
4
A>=B means
A is greater than or equal to B
B is greater than or equal to A
A is less than or equal to B
The _______ loop executes a set of instructions as long as a given condition is true.
For...Next Loop
Do your best Loop
Do Until.....Loop
Do While....Loop
The ________ loop is used to repeatedly execute a statement or a block of statements for the specified number of times.
FOR...NEXT loop
Do......Loop
Do While
If no STEP is used with the FOR statement, the control variable is incremented by the default value, which is ___.
1
2
3
4
x = 2
DO WHILE x <= 8
PRINT x
x = x + 2
LOOP
2 4 6 8
2 4 6 8 10
2 4 6
Infinite loop
