wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Understanding Loops in C Programming

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is a for loop used for?

a)

To create a new variable

b)

To define a function

c)

To sort a list of items

d)

To repeat a block of code a specific number of times or to iterate over elements in a collection.

2.

How do you start a while loop?

a)

while (condition) { // code to execute }

b)

do { // code to execute } while (condition)

c)

repeat (condition) { // code to execute }

d)

for (condition) { // code to execute }

3.

What is a nested loop?

a)

A nested loop is a loop within another loop.

b)

A loop that can only be used in functions.

c)

A loop that runs indefinitely without any conditions.

d)

A loop that only executes once.

4.

Which statement can stop a loop?

a)

break

b)

skip

c)

continue

d)

exit

5.

How do you loop through an array?

a)

Use a for loop, forEach, or for...of to iterate through the array.

b)

Use a switch statement to access array elements.

c)

You cannot loop through an array in JavaScript.

d)

Use a while loop to iterate through the array.

6.

What happens in an infinite loop?

a)

An infinite loop only runs when triggered by user input.

b)

An infinite loop stops after a certain condition is met.

c)

An infinite loop runs indefinitely without stopping.

d)

An infinite loop runs for a fixed number of iterations.

7.

What is the syntax for a for loop?

a)

for (initialization; condition; increment) { // code to execute }

b)

for (initialization; increment) { // code to execute } while (condition)

c)

for { // code to execute } (initialization; condition; increment)

d)

for (condition; initialization; increment) { // code to execute }

8.

When does a while loop stop?

a)

When the loop is manually interrupted.

b)

When the loop runs for a set number of iterations.

c)

When the condition evaluates to false.

d)

When the program encounters an error.

9.

Can you have a loop inside another loop?

a)

No, loops cannot be nested.

b)

Yes, you can have a loop inside another loop.

c)

Only one loop is allowed in a program.

d)

Loops can only run sequentially, not inside each other.

10.

What does 'break' do in a loop?

a)

The 'break' statement restarts the loop from the beginning.

b)

The 'break' statement skips the current iteration of the loop.

c)

The 'break' statement exits the loop.

d)

The 'break' statement pauses the loop.

11.

How do you access elements in an array using a loop?

a)

Use a for loop or forEach method to iterate through the array and access elements by their index.

b)

Access elements using a while loop only.

c)

Use a switch statement to access array elements.

d)

Access elements by their value instead of index.

12.

What is the main purpose of loops in programming?

a)

The main purpose of loops in programming is to execute a block of code multiple times.

b)

To create functions in programming.

c)

To improve the performance of a program.

d)

To store data in a variable.

13.

What is the condition in a while loop?

a)

An array of values to be processed in the loop.

b)

A numeric value that counts iterations.

c)

A string that describes the loop's purpose.

d)

A boolean expression that determines if the loop continues.

14.

What is an example of an infinite loop?

a)

while(true) { // code }

b)

for(int i = 0; i < 10; i++) { // code }

c)

if(condition) { // code }

d)

do { // code } while(false);

15.

How do you use 'continue' in a loop?

a)

Use 'continue' to end the loop immediately.

b)

Use 'continue' to restart the loop from the beginning.

c)

Use 'continue' to skip the current iteration in a loop.

d)

Use 'continue' to pause the loop for a specified time.