control statements

control statements

University

13 Qs

quiz-placeholder

Similar activities

Coding Fundamentals in C

Coding Fundamentals in C

6th Grade - Professional Development

12 Qs

Python Basics

Python Basics

University

15 Qs

Python Loops

Python Loops

University

17 Qs

Loops-2

Loops-2

University

15 Qs

SOAL MODUL 4 : Pemahaman Looping dan Kondisional

SOAL MODUL 4 : Pemahaman Looping dan Kondisional

10th Grade - University

10 Qs

C++Arrays Loops and Functions Review

C++Arrays Loops and Functions Review

University

15 Qs

ITC303 QUIZ #3

ITC303 QUIZ #3

University

10 Qs

Loop

Loop

University

15 Qs

control statements

control statements

Assessment

Quiz

Computers

University

Hard

Created by

thanga_palani_ thanga_palani_

FREE Resource

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.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?