wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Understanding Loops in C

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the basic syntax of a for loop in C?

a)

for(initialization; condition) { // code }

b)

for(initialization; condition; increment/decrement) { // code to be executed }

c)

for(initialization; increment/decrement; condition) { // code }

d)

for(condition; initialization; increment/decrement) { // code }

2.

How does a while loop differ from a for loop in structure?

a)

A while loop requires a counter variable, while a for loop does not.

b)

A for loop can only iterate over arrays, while a while loop cannot.

c)

A while loop focuses on a condition, while a for loop includes initialization, condition, and increment in its structure.

d)

A while loop is always faster than a for loop.

3.

What is the purpose of a do-while loop in C?

a)

To create an infinite loop without any condition.

b)

The purpose of a do-while loop in C is to execute a block of code at least once and then repeat it based on a condition.

c)

To execute a block of code only if a condition is true.

d)

To execute a block of code based on user input only.

4.

Can you explain how nested loops work with an example?

a)

The outer loop iterates through each column, and the inner loop iterates through each row.

b)

For a 2D array, the outer loop iterates through each row, and the inner loop iterates through each column in that row.

c)

Each loop must have the same number of iterations.

d)

Nested loops can only be used with 1D arrays.

5.

What are loop control statements and how are they used?

a)

loop control statements are used to declare variables

b)

loop control statements include 'if' and 'else'

c)

Loop control statements are 'break', 'continue', and 'return', used to control the execution flow in loops.

d)

loop control statements are only used in functions

6.

What is an infinite loop and how can it occur in C?

a)

An infinite loop occurs when a loop is executed in a separate thread.

b)

An infinite loop is a loop that never terminates due to a condition that is always true.

c)

An infinite loop is a loop that runs for a fixed number of iterations.

d)

An infinite loop is a loop that always terminates after a certain condition.

7.

How do you break out of a loop using control statements?

a)

Use the 'exit' statement to terminate the program.

b)

Use the 'return' statement to exit a loop.

c)

Use the 'continue' statement to exit a loop.

d)

Use the 'break' statement to exit a loop.

8.

What is the difference between pre-test and post-test loops?

a)

Pre-test loops execute once before checking the condition; post-test loops execute multiple times before checking.

b)

Pre-test loops check the condition after execution; post-test loops check before execution.

c)

Pre-test loops check the condition before execution; post-test loops check after execution.

d)

Pre-test loops can only be used in conditional statements; post-test loops can only be used in iterations.

9.

Can you provide an example of a nested for loop?

a)

for j in range(3): for i in range(2): print(j)

b)

for i in range(3): for j in range(2): print(i, j)

c)

for i in range(5): print(i)

d)

for i in range(2): for j in range(3): print(i + j)

10.

What are common mistakes to avoid when using loops in C?

a)

Loop conditions should always be true to avoid infinite loops

b)

Common mistakes to avoid when using loops in C include forgetting to initialize variables, not updating loop variables, incorrect loop conditions, modifying loop variables inside the loop, and not using braces for multi-statement loops.

c)

Initializing loop variables inside the loop is best practice

d)

Using a single statement without braces is always correct

11.
Which operator is used for addition in spreadsheets?
a)
*
b)
+
c)
&
d)
/
12.
In spreadsheets, the operator ^ is used for:
a)
Division
b)
Multiplication
c)
Exponentiation (power)
d)
Percentage
13.
Which operator is used to join (concatenate) text in Excel?
a)
+
b)
&
c)
#
d)
%
14.
What will the formula =10/2*5 return in a spreadsheet?
a)
1
b)
25
c)
2
d)
50
15.
Which of the following represents the modulus (remainder) operation in Excel?
a)
%
b)
MOD() function
c)
#
d)
^
16.
In spreadsheets, comparison operators are used to:
a)
Perform arithmetic
b)
Compare two values
c)
Format cells
d)
Insert functions
17.
What will the formula =5>3 return in Excel?
a)
2
b)
5
c)
TRUE
d)
FALSE
18.
Which of the following is NOT a valid comparison operator in spreadsheets?
a)
=
b)
<>
c)
<=
d)
:=
19.
If cell A1 contains 7 and A2 contains 3, what will =A1^A2 return?
a)
10
b)
21
c)
343
d)
73
20.
Which operator has the highest precedence in spreadsheets?
a)
^ (Exponentiation)
b)
* (Multiplication)
c)
+ (Addition)
d)
= (Equal to)