Introduction to Loops Quiz - CBSE Class 8 ICT
Free practice quiz: Introduction to Loops (CBSE Class 8 ICT). 19 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 19 questions freeSample questions
What is a loop in programming?
- A method to repeat a set of instructions
- A condition to stop a program
- A variable that counts
- A type of data structure
Show answer
Answer: A. A method to repeat a set of instructions
A loop is a fundamental concept in programming that allows a set of instructions to be executed repeatedly until a certain condition is met.
In a 'while' loop, when does the loop terminate?
- When the condition evaluates to false
- After a set number of iterations
- Immediately
- Before the first iteration
Show answer
Answer: A. When the condition evaluates to false
A 'while' loop continues to execute as long as the condition remains true. It stops when the condition becomes false.
How does a 'do-while' loop differ from a 'while' loop?
- A 'do-while' loop executes at least once before checking the condition
- A 'do-while' loop cannot run at all
- A 'do-while' loop checks condition before execution
- They are identical
Show answer
Answer: A. A 'do-while' loop executes at least once before checking the condition
Unlike 'while' loops, 'do-while' loops guarantee at least one execution of their block of code, as the condition is checked after the execution.
What will be the final value of 'i' after the following code is executed? 'int i = 0; while(i < 5) { i++; }'
- 0
- 5
- 6
- 4
Show answer
Answer: B. 5
The while loop increments 'i' until it is no longer less than 5, resulting in a final value of 5.
How many times will 'print()' be called in the following code? 'for(int i=1; i<6; i+=2) { print(); }'
- 2
- 3
- 5
- 4
Show answer
Answer: B. 3
The loop increments by 2, resulting in calls when i equals 1, 3, and 5—totaling three calls to print().