wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Gr 7 - QBASIC LOOPS

Total questions: 36

Worksheet time: 35mins

Name
Class
Date
1.

Identify the counter variable in the given program

FOR i = 1 TO 4

PRINT “computer”

NEXT

(a)  

2.

Identify the Initial value in the given program

FOR i = 1 TO 11

PRINT “5”

NEXT i

(a)  

3.

1. A repeated execution of statements for a fixed number of times is known as________

a)

Loop

b)

Repeat

c)

Again

d)

execution

4.

2. The number of times the for next loop gets executed is based on the difference between ______________ value.

a)

n value

b)

start value and end value

c)

maximum value

d)

x and y value

5.

3. To execute a group of statements for a specific number of times ___________ loop is used.

a)

for next

b)

while

c)

do while

d)

do until

6.

What will be the output of the following code?
FOR i = 1 TO 5

PRINT i

NEXT

a)

1 2 3 4 5 6

b)

1 2 3 4 5

c)

5 4 3 2 1

d)

1 2 3 4

7.

i = 5

DO UNTIL i > 7

PRINT i;

i = i + 1

LOOP

a)

5 6 7

b)

5 6

c)

5 6 7 8

d)

5

8.

What will be the output of the following code?
FOR i = 1 TO 6 STEP 2

PRINT i;

NEXT

a)

1 3 5

b)

1 2 3 4 5 6

c)

2 4 6

d)

1

9.

What will be the output of the following code?
FOR i = 16 TO 61 STEP -2

PRINT i;

NEXT

a)

10 8 6

b)

10 8

c)

10 9 8 7 6

d)

No output

10.

i = 10

DO WHILE i >= 7

PRINT i;

i = i - 1

LOOP

a)

10 9 8 7

b)

10 9 8

c)

10

d)

No output

11.

What will happen if the following code is executed?

FOR i = 1 TO 5

PRINT i;

NEXT

a)

The loop will execute and print numbers from 1 to 5.

b)

There will be a syntax error because of ; symbol

c)

The code will run but skip one iteration.

d)

The program will not execute due to missing snack and drink

12.

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

a)

There is no termination condition for the loop

b)

The value of i is increasing indefinitely

c)

All answers are correct

d)

The condition is always true

13.

How can you avoid an infinite loop in this code?

a)

Add a decrement statement for i

b)

Change the condition to DO WHILE i < 5

c)

Use a FOR loop instead of a DO WHILE loop

d)

All wrong

14.

How does the use of STEP in the following code affect execution?

FOR i = 10 TO 1 STEP -2

PRINT i;

NEXT

a)

The loop decrements i by 2 after each iteration

b)

The loop increments i by 2 after each iteration

c)

The loop terminates immediately because of a negative STEP

d)

All wrong

15.

Why does the following code result in no output?

FOR i = 1 TO 0 STEP 1

PRINT i;

NEXT

a)

The condition 1 TO 0 makes the loop invalid

b)

The STEP 1 ensures no iterations occur

c)

The loop starts with an invalid range

d)

All wrong

16.

What happens if the LOOP statement is omitted (Deleted) from this code?

i = 1

DO WHILE i <= 3

PRINT i;

i = i + 1

LOOP

a)

The loop will run indefinitely

b)

The program will throw an error

c)

The program will execute only once

d)

All wrong

17.

What is a FOR...NEXT loop in QBasic?

a)

A loop that runs until a condition is false

b)

A loop with a fixed number of iterations

c)

A loop that runs indefinitely

d)

A loop that executes at least once regardless of condition

18.

Which statement best defines a DO WHILE loop in QBasic?

a)

A loop that runs a fixed number of times

b)

A loop that repeats as long as the condition is true

c)

A loop that executes before the condition

d)

A loop that increments a variable automatically

19.

What is the purpose of a DO UNTIL loop?

a)

To execute a set of statements until the condition becomes true

b)

To execute statements until a variable reaches a specific value

c)

To execute a loop indefinitely

d)

To count iterations automatically

20.

What is the difference between DO WHILE and DO UNTIL loops?

a)

DO UNTIL runs as long as the condition is true, while DO WHILE runs until the condition becomes true

b)

DO WHILE runs as long as the condition is true, while DO UNTIL runs until the condition becomes true

c)

DO WHILE only works with numeric values, while DO UNTIL does not

d)

There is no difference between them

21.

What does the STEP keyword in a FOR...NEXT loop define?

a)

It is used for decoration

b)

The condition for exiting the loop

c)

The increment (or decrement) value for each iteration

d)

The starting value of the loop variable

22.

FOR i = 1 TO 3

PRINT i

NEXT

a)

1 2 3

b)

1 2 3 4

c)

0 1 2 3

d)

3 2 1

23.

x = 10

DO WHILE x > 5

PRINT x

x = x - 2

LOOP

a)

10 8 6

b)

10 8

c)

10 8 6 4

d)

Infinite loop

24.

Which of the following best describes the behavior of this code?
x = 5

DO UNTIL x = 0

PRINT x

x = x - 2

LOOP

a)

Prints numbers 5, 3, 1

b)

Prints numbers 5, 3, 1, -1

c)

Infinite loop

d)

Does not print anything

25.

rue or False: The following code does not work

FOR i = 1 TO 10 STEP -1

PRINT i

NEXT

a)

True

b)

False

26.

Analyze the behavior of this code and select all correct statements.

x = 5

DO WHILE x <= 15

PRINT x

x = x + 3

LOOP

a)

Prints numbers starting from 5 to 15, incrementing by 3

b)

Last number printed is 17

c)

The loop runs 5 times

d)

The loop runs 4 times

27.

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

a)

True

b)

False

28.

Which of the following will create an infinite loop?

a)

FOR i = 1 TO 5

PRINT i

NEXT i

b)

x=1

DO WHILE x > 0

PRINT x

LOOP

c)

x=0

DO UNTIL x < 0

PRINT x

LOOP

d)

All wrong

29.

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

30.
a)
b)
c)
d)
31.

5. ____________________ types of Do loops are available in QBasic.

a)

2

b)

1

c)

3

d)

4

32.

A>=B means

a)

A is greater than or equal to B

b)

B is greater than or equal to A

c)

A is less than or equal to B

33.

The _______ loop executes a set of instructions as long as a given condition is true.

a)

For...Next Loop

b)

Do your best Loop

c)

Do Until.....Loop

d)

Do While....Loop

34.

The ________ loop is used to repeatedly execute a statement or a block of statements for the specified number of times.

a)

FOR...NEXT loop

b)

Do......Loop

c)

Do While

35.

If no STEP is used with the FOR statement, the control variable is incremented by the default value, which is ___.

a)

1

b)

2

c)

3

d)

4

36.

x = 2

DO WHILE x <= 8

PRINT x

x = x + 2

LOOP

a)

2 4 6 8

b)

2 4 6 8 10

c)

2 4 6

d)

Infinite loop