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.
This CBSE Class 8 ICT practice quiz has 19 multiple-choice questions on Introduction to Loops, and 19 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 19 questions, freeSample questions
What is a loop in programming?
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?
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?
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++; }'
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(); }'
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().
More questions in this quiz
Answers and explanations are in the full quiz.
- Which of the following is NOT a type of loop?
- What does a 'for' loop do?
- What is an infinite loop?
- Which of the following can cause an infinite loop?
- What is the purpose of a 'break' statement in a loop?
- If a for loop iterates 5 times and has a break statement that is executed on the 3rd iteration, how many times will the loop actually run?
- What is the output of the following code? 'for(int i=0; i<5; i++) { if (i == 3) break; print(i); }'
- In which situation would you prefer a 'while' loop over a 'for' loop?
- If you have nested loops, how many times will the inner loop run if the outer loop runs 3 times and the inner loop runs 4 times?
- What is the value of 'total' after the following code is executed? 'int total=0; for(int i=1; i<=3; i++) { total+=i; }'
- What will happen if the condition in a 'for' loop is always true?
- What is the effect of adding 'continue' inside a loop?
- In nested loops, which loop runs more times?
- Why is it important to use a terminating condition in loops?
More quizzes
Browse all Programming Basics quizzes