Search Header Logo

While Loop

Authored by Umar Golamaully

Computers

10th Grade

While Loop
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the main purpose of a 'While' loop in programming?

To repeat a set of instructions a specific number of times

To repeat a set of instructions as long as a condition is true

To declare variables

To print text on the screen

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

If the condition in a 'While' loop is initially false, how many times will the loop execute?

1 time

0 times

Infinite times

Depends on the code inside the loop

Answer explanation

The condition for 'While' loop is checked at the start. If at the very start of the loop, the condition evaluates to False, then the code inside the loop will not be executed at all.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In VB, what keyword is used to mark the end of a 'While' loop?

End While

Next

End Loop

Loop Until

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the following VB code if X is set to 1 (X = 1) before the start of the 'While' loop?

Hello

Hello

Hello

Hello

Hello

Hello

Infinite Loop

Answer explanation

X is initially 1. (X = 1)

As long as the condition X <= 3 in the While loop is true, the word "Hello" will be printed on screen.

X is incremented by 1 (X = X + 1) to prevent infinite loop.

So, "Hello" will be printed 3 times (when X = 1, X = 2 and X = 3).

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

Identify the error in this VB code.

The 'While' keyword is incorrect

The condition i >= 1 is incorrect

The loop does not update the value of variable i, causing an infinite loop

The loop will not execute at all

Answer explanation

The value of i is initially 10.

The While keyword is correctly written.

The condition of the While loop is true (since i >= 1).

The loop will be executed and the value of i will be printed on screen.

But notice that the the value of i is not decremented before the 'While' loop ends.

This causes i to remain at value 10 each time the loop executes, causing infinite loop.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?