wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Loop Logic Challenge – C Basics Edition

Total questions: 30

Worksheet time: 24mins

Name
Class
Date
1.

A toy car needs to complete 5 laps around a track. Each lap, the distance increases by 1 meter. Which loop structure is most suitable for tracking this in C?

a)

do...while loop

b)

while loop

c)

for loop

d)

goto statement

2.

What will be the output of the following code?

a)

1 2 3

b)

2 4 6

c)

2 3 4

d)

1 3 5

3.

Find the error in the code below:

a)

No error

b)

while should be replaced with for

c)

Missing braces {} after while

d)

i should be initialized to 0

4.

What is the value of sum after this loop runs?

a)

10

b)

6

c)

4

d)

8

5.

What does the following loop print?

a)

b)

c)

d)

no output

6.

Which of the following code snippets will result in an infinite loop?

a)

for(int i = 0; i < 5; i++)

b)

while(1)

c)

for(;;)

d)

while(i++ < 3)

7.

To repeat a task exactly 10 times, the best loop to use is:

a)

while loop

b)

goto

c)

for loop

d)

switch

8.

Choose the Output

a)

1 2 3

b)

0 1 2

c)

1 2 3 4

d)

1 2 3

9.

A vending machine dispenses snacks every time a button is pressed until the snacks run out. Which loop is most suitable for this logic?

a)

for loop

b)

do...while loop

c)

while loop

d)

switch statement

10.

In a game, the player collects one coin every second until they have 100 coins. Which of the following loops is ideal for this?

a)

for(i = 1; i <= 100; i++)

b)

while(coins != 100)

c)

do { coins++; } while(coins < 100);

d)

All of the above

11.

Convert the for loop below into a while loop:

a)

b)

c)

d)

12.

A robot is programmed to clean rooms until the battery is less than 10%. Which loop fits best?

a)

for(i = 100; i > 10; i -= 10)

b)

while(battery >= 10)

c)

do...while

d)

if loop

13.

Which loop will definitely execute at least once, even if the condition is false?

a)

for loop

b)

while loop

c)

do...while loop

d)

All of the above

14.

A traffic light stays green for 10 seconds, then switches to red and repeats this cycle continuously.
Which loop structure would best simulate this repeated timing in a traffic system?

a)

for loop

b)

while(1) loop

c)

if...else

d)

do...while

15.

An ATM allows only 3 incorrect PIN attempts before locking the account. What is the best way to implement this?

a)

while(pin != correctPin)

b)

for(i = 0; i < 3; i++)

c)

while(1)

d)

do...while

16.

An elevator moves floor by floor from ground (0) to the 10th floor. Which loop structure fits best?

a)

while(floor <= 10)

b)

for(floor = 0; floor <= 10; floor++)

c)

do...while(floor < 10)

d)

All of the above

17.

A user must enter the correct password. The system keeps asking until it's correct.
Which loop best fits this logic?

a)

for(i = 0; i < 3; i++)

b)

do...while(password != correct)

c)

while(password != correct)

d)

for(i = 0; i < correct; i++)

18.

Each time a user books a ticket, the number of available seats should reduce. Stop booking when no seats are left.

a)

for(i = seats; i > 0; i--)

b)

while(seats > 0)

c)

do...while(seats > 0)

19.

What is the minimum number of times a do...while loop executes?

a)

0

b)

1

c)

Infinite

d)

Depends on condition

20.

Which symbol is used for "equal to" comparison in C?

a)

=

b)

==

c)

===

d)

!=

21.

What will happen if the condition in an if statement is false and there is no else part?

a)

Program crashes

b)

Nothing happens

c)

Code runs anyway

d)

Error occurs

22.

Which of the following is a valid C program entry point?

a)

start()

b)

main()

c)

int main()

d)

void start()

23.

What is the result of 5 % 2 in C?

a)

2

b)

2.5

c)

1

d)

0

24.

What does return 0; mean in main()?

a)

Ends the loop

b)

Terminates the program successfully

c)

Returns 0 to the printf()

d)

Starts the program

25.

Who is the founder of the C programming language?

a)

Bjarne Stroustrup

b)

Dennis Ritchie

c)

Ken Thompson

d)

Brian Kernighan

26.

In which year was the C programming language developed?

a)

1970

b)

1972

c)

1962

d)

1965

27.

Which operating system was initially developed using the C programming language?

a)

Windows

b)

UNIX

c)

Linux

d)

DOS

28.

Which of these programming languages influenced the development of C?

a)

ALGOL 60

b)

FORTRAN

c)

COBOL

d)

Pascal

29.

Which of the following is a direct successor of the C language?

a)

Java

b)

C++

c)

Python

d)

Ruby

30.

The C programming language was initially developed for which type of systems?

a)

Microcontrollers

b)

Personal computers

c)

Mainframe computers

d)

Embedded systems