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

  1. Q1Multiple choice1 mark
    Which nested loop structure is appropriate for finding the sum of the series: S=1!+2!+3!+⋯+n!S = 1! + 2! + 3! + \dots + n!?
    1. (a)An inner loop running up to nn for every term and an outer loop adding each result to the sum.
    2. (b)A factorial variable set to 1 once before both loops, multiplied by the inner loop for each term.
    3. (c)An inner loop to compute factorial and an outer loop that resets the sum to 0 for each term.
    4. (d)An inner loop to compute factorial and an outer loop to accumulate the sum up to nn.
    Show answer and step marks
    1. Correct option: (d) An inner loop to compute factorial and an outer loop to accumulate the sum up to nn.+1
    Answer: (d)
  2. Q2Assertion and reason1 mark
    Assertion (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.
    1. (a)Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of Assertion (A).
    2. (b)Both Assertion (A) and Reason (R) are true but Reason (R) is not the correct explanation of Assertion (A).
    3. (c)Assertion (A) is true but Reason (R) is false.
    4. (d)Assertion (A) is false but Reason (R) is true.
    Show answer and step marks
    1. Correct option: (a) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of Assertion (A).+1
    Answer: (a)
  3. Q3Multiple choice1 mark
    In 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:
    1. (a)the termination condition of the inner loop directly
    2. (b)the number of rows in the pattern
    3. (c)the number of columns in each row
    4. (d)the spacing between characters
    Show answer and step marks
    1. Correct option: (b) the number of rows in the pattern+1
    Answer: (b)
  4. Q4Short answer2 marks
    Explain the purpose of a labelled continue statement in Java. Provide a brief illustrative syntax.
    Show answer and step marks
    1. 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
    2. 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); } }
  5. Q5Short answer3 marks
    Study 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
    1. Row 1: i = 1, so j runs from 4 down to 1, printing 4, 3, 2, 1, giving 4321+0.5
    2. Row 2: i = 2, so j runs from 4 down to 2, printing 4, 3, 2, giving 432+0.5
    3. Row 3: i = 3, so j runs from 4 down to 3, printing 43+1
    4. Row 4: i = 4, so j runs from 4 down to 4, printing 4+1
    Answer: 4321 432 43 4
  6. Q6Long answer4 marks
    Write 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
    1. Correct class declaration and main method structure.+0.5
    2. Outer loop for the rows: for (int i = 1; i ≤ 4; i++).+1
    3. Inner loop for the columns: for (int j = 1; j ≤ i; j++).+1
    4. Inside the inner loop, print the product with a space: System.out.print(i × j + " ");+1
    5. 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
See a sample marked answer sheet

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

More Class 9 Computer Applications mock tests