The Table Weaver

EasyAcc. 91.8%
+20 XP 8

Multi-Level Multiplication

A single loop is powerful, but nested while loops allow you to weave complex sequences. By controlling two independent counters, you can process rows and columns separately.

The Assignment

Your function receives parameters rows and cols.

  1. Declare two variables: i (outer) and j (inner), both starting at 1.
  2. Write an outer while loop that continues while i is less than or equal to rows.
  3. Inside the outer loop, ensure j is reset to 1 before the inner loop starts.
  4. Write an inner while loop that continues while j is less than or equal to cols.
  5. Inside the inner loop:
    • Print the product of i and j.
    • Advance the value of j.
  6. After the inner loop finishes, advance the value of i.

01EXAMPLE 1

Inputrows=2, cols=5
Output1 2 3 4 5 2 4 6 8 10

Explanation: Prints row 1 products, then row 2 products.

02EXAMPLE 2

Inputrows=1, cols=3
Output1 2 3

Explanation: One row, three products.

Constraints

  • Use strictly nested while loops.
  • Print each product on a new line.
LoopsNested LoopsFundamentals
JavaScript
Loading...
3 Hidden

Input Arguments

rows2
cols5

Expected Output

1
2
3
4
5
2
4
6
8
10

Click RUN to test your solution