control statements

control statements

University

13 Qs

quiz-placeholder

Similar activities

SQL Quiz

SQL Quiz

University

18 Qs

Computer Network Fun Review 5 - Data Link Layer

Computer Network Fun Review 5 - Data Link Layer

University

10 Qs

SMITE 6.0: Get to Know Cybersecurity

SMITE 6.0: Get to Know Cybersecurity

University

11 Qs

วิทยาการคำนวณ p.5

วิทยาการคำนวณ p.5

University

10 Qs

Semiconductores

Semiconductores

University

10 Qs

Memory-Mobo-Hard/Software

Memory-Mobo-Hard/Software

University

18 Qs

Archivos Digitales

Archivos Digitales

9th Grade - University

14 Qs

Jaringan Dasar

Jaringan Dasar

University

10 Qs

control statements

control statements

Assessment

Quiz

Computers

University

Practice Problem

Hard

Created by

thanga_palani_ thanga_palani_

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

13 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the break statement do in a loop?

Restarts the loop

Skips the current step

Exits the loop completely

Makes the loop run forever

Answer explanation

The break statement is used in loops to exit the loop completely, terminating its execution. This means that when a break is encountered, the loop stops running, and control is transferred to the statement following the loop.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the continue statement do?

Ends the loop

Skips the rest of the loop and moves to next iteration

Skips the rest of the loop and moves to next iteration

Skips input

Answer explanation

The continue statement skips the rest of the current loop iteration and proceeds to the next iteration. This means any code after the continue statement within the loop will not execute for that iteration.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will this code output?

for i in range(5):

if i == 3:

break

print(i)

0 1 2

0 1 2 3 4

1 2 3

0 1 2 3

Answer explanation

The loop iterates from 0 to 4. When i is 3, the 'break' statement exits the loop. Thus, only 0, 1, and 2 are printed before the loop is terminated. Therefore, the output is '0 1 2', making it the correct choice.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output?

for i in range(5):

if i == 3:

continue

print(i)

0 1 2 3 4

1 2 3

0 1 2 4

0 1 2

Answer explanation

The loop iterates from 0 to 4. When i is 3, the 'continue' statement skips the print. Thus, the output is 0, 1, 2, and 4, making the correct answer '0 1 2 4'.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a while loop, where is break used?

Inside a condition

Inside the loop block

Outside the loop

After loop ends

Answer explanation

The 'break' statement is used inside the loop block to exit the loop prematurely when a specific condition is met. This allows for more control over the loop's execution, making 'Inside the loop block' the correct choice.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What happens if break is not used?

Loop stops

Loop continues normally

Syntax error

System shuts down

Answer explanation

If 'break' is not used in a loop, the loop continues normally, executing all iterations until its condition is no longer met. This means the loop will run to completion unless interrupted by other means.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does this print?

i = 0 while i < 5:

i += 1

if i == 3:

continue

print(i)

1 2 3 4 5

1 2 4 5

1 2 3 5

0 1 2 3

Answer explanation

The loop increments i from 0 to 5. When i equals 3, the 'continue' statement skips the print, so 3 is not printed. The output is 1, 2, 4, and 5, making '1 2 4 5' the correct answer.

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?

Discover more resources for Computers