ICSE · Class 9 · Computer Applications
Class 9 Nested Loops Mock Test (ICSE)
6 practice questions from Nested Loops, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.
Topics in Nested Loops
- Nested for loops
- Patterns using nested loops
- Series using nested loops
- Labelled break and continue
Nested Loops practice questions with answers
- Q1Multiple choice1 markWhich nested loop structure is appropriate for finding the sum of the series: ?
- (a)An inner loop running up to for every term and an outer loop adding each result to the sum.
- (b)A factorial variable set to 1 once before both loops, multiplied by the inner loop for each term.
- (c)An inner loop to compute factorial and an outer loop that resets the sum to 0 for each term.
- (d)An inner loop to compute factorial and an outer loop to accumulate the sum up to .
Show answer and step marks
- Correct option: (d) An inner loop to compute factorial and an outer loop to accumulate the sum up to .+1
Answer: (d) - Q2Assertion and reason1 markAssertion (A): A labelled break can exit an outer loop from inside an inner loop. Reason (R): A plain break only terminates the innermost loop that contains it.
- (a)Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of Assertion (A).
- (b)Both Assertion (A) and Reason (R) are true but Reason (R) is not the correct explanation of Assertion (A).
- (c)Assertion (A) is true but Reason (R) is false.
- (d)Assertion (A) is false but Reason (R) is true.
Show answer and step marks
- Correct option: (a) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of Assertion (A).+1
Answer: (a) - Q3Multiple choice1 markIn a nested loop used to print a right-angled triangle pattern of numbers where the row number dictates the number of columns, the outer loop typically controls:
- (a)the termination condition of the inner loop directly
- (b)the number of rows in the pattern
- (c)the number of columns in each row
- (d)the spacing between characters
Show answer and step marks
- Correct option: (b) the number of rows in the pattern+1
Answer: (b) - Q4Short answer2 marksExplain the purpose of a labelled continue statement in Java. Provide a brief illustrative syntax.
Show answer and step marks
- State that a labelled continue skips the remaining statements of the current iteration of the specified outer loop and proceeds to its next iteration.+1
- Provide correct syntax usage: outer: for(...) { for(...) { continue outer; } }+1
Answer: A labelled continue skips the rest of the current iteration of the labelled (outer) loop and continues with that loop's next iteration. Syntax: outer: for (int i = 1; i ≤ 3; i++) { for (int j = 1; j ≤ 3; j++) { if (j == 2) continue outer; System.out.println(i + " " + j); } } - Q5Short answer3 marksStudy the Java code fragment below and write the exact output it prints. Write each line of output on a separate line. for (int i = 1; i ≤ 4; i++) { for (int j = 4; j ≥ i; j--) { System.out.print(j); } System.out.println(); }
Show answer and step marks
- Row 1: i = 1, so j runs from 4 down to 1, printing 4, 3, 2, 1, giving 4321+0.5
- Row 2: i = 2, so j runs from 4 down to 2, printing 4, 3, 2, giving 432+0.5
- Row 3: i = 3, so j runs from 4 down to 3, printing 43+1
- Row 4: i = 4, so j runs from 4 down to 4, printing 4+1
Answer: 4321 432 43 4 - Q6Long answer4 marksWrite a program in Java using nested for loops to display the following triangular pattern: 1 2 4 3 6 9 4 8 12 16
Show answer and step marks
- Correct class declaration and main method structure.+0.5
- Outer loop for the rows: for (int i = 1; i ≤ 4; i++).+1
- Inner loop for the columns: for (int j = 1; j ≤ i; j++).+1
- Inside the inner loop, print the product with a space: System.out.print(i × j + " ");+1
- System.out.println(); after the inner loop to move to the next row.+0.5
Answer: public class Pattern { public static void main(String[] args) { for (int i = 1; i ≤ 4; i++) { for (int j = 1; j ≤ i; j++) { System.out.print(i × j + " "); } System.out.println(); } } } Output: 1 2 4 3 6 9 4 8 12 16
Take a full Nested Loops test
PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.
- 15 min10 marks
- 30 min20 marks
- 1.5 hr40 marks
- 3 hr80 marks
Get your Nested Loops answers marked
Sign in, pick this chapter and a length, write the test on paper and get every step marked.
Sign in to take this test