Font size
WorksheetsLoop Logic Challenge – C Basics Edition
Total questions: 30
Worksheet time: 24mins
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?
do...while loop
while loop
for loop
goto statement
What will be the output of the following code?
1 2 3
2 4 6
2 3 4
1 3 5
Find the error in the code below:
No error
while should be replaced with for
Missing braces {} after while
i should be initialized to 0
What is the value of sum after this loop runs?
10
6
4
8
What does the following loop print?
no output
Which of the following code snippets will result in an infinite loop?
for(int i = 0; i < 5; i++)
while(1)
for(;;)
while(i++ < 3)
To repeat a task exactly 10 times, the best loop to use is:
while loop
goto
for loop
switch
Choose the Output
1 2 3
0 1 2
1 2 3 4
1 2 3
A vending machine dispenses snacks every time a button is pressed until the snacks run out. Which loop is most suitable for this logic?
for loop
do...while loop
while loop
switch statement
In a game, the player collects one coin every second until they have 100 coins. Which of the following loops is ideal for this?
for(i = 1; i <= 100; i++)
while(coins != 100)
do { coins++; } while(coins < 100);
All of the above
Convert the for loop below into a while loop:
A robot is programmed to clean rooms until the battery is less than 10%. Which loop fits best?
for(i = 100; i > 10; i -= 10)
while(battery >= 10)
do...while
if loop
Which loop will definitely execute at least once, even if the condition is false?
for loop
while loop
do...while loop
All of the above
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?
for loop
while(1) loop
if...else
do...while
An ATM allows only 3 incorrect PIN attempts before locking the account. What is the best way to implement this?
while(pin != correctPin)
for(i = 0; i < 3; i++)
while(1)
do...while
An elevator moves floor by floor from ground (0) to the 10th floor. Which loop structure fits best?
while(floor <= 10)
for(floor = 0; floor <= 10; floor++)
do...while(floor < 10)
All of the above
A user must enter the correct password. The system keeps asking until it's correct.
Which loop best fits this logic?
for(i = 0; i < 3; i++)
do...while(password != correct)
while(password != correct)
for(i = 0; i < correct; i++)
Each time a user books a ticket, the number of available seats should reduce. Stop booking when no seats are left.
for(i = seats; i > 0; i--)
while(seats > 0)
do...while(seats > 0)
What is the minimum number of times a do...while loop executes?
0
1
Infinite
Depends on condition
Which symbol is used for "equal to" comparison in C?
=
==
===
!=
What will happen if the condition in an if statement is false and there is no else part?
Program crashes
Nothing happens
Code runs anyway
Error occurs
Which of the following is a valid C program entry point?
start()
main()
int main()
void start()
What is the result of 5 % 2 in C?
2
2.5
1
0
What does return 0; mean in main()?
Ends the loop
Terminates the program successfully
Returns 0 to the printf()
Starts the program
Who is the founder of the C programming language?
Bjarne Stroustrup
Dennis Ritchie
Ken Thompson
Brian Kernighan
In which year was the C programming language developed?
1970
1972
1962
1965
Which operating system was initially developed using the C programming language?
Windows
UNIX
Linux
DOS
Which of these programming languages influenced the development of C?
ALGOL 60
FORTRAN
COBOL
Pascal
Which of the following is a direct successor of the C language?
Java
C++
Python
Ruby
The C programming language was initially developed for which type of systems?
Microcontrollers
Personal computers
Mainframe computers
Embedded systems
