Skip to Content
Practice CornerNested Loops

Nested Loops

Nested loops are loops inside loops. They allow us to perform operations on multi-dimensional data structures or execute repeated actions within an iterative process. Practice these problems to strengthen your understanding of nested loops.

Practice Problems

Problems Index

  1. Print a square pattern of * with n rows and columns.
  2. Print a right-angled triangle pattern of *.
  3. Generate a multiplication table up to n.
  4. Create a pyramid pattern of numbers.
  5. Print the following pattern for n:
    1 12 123 1234
  6. Input a list of lists and calculate the sum of all elements.
  7. Print all pairs of elements from two lists.
  8. Find the transpose of a 2D matrix.
  9. Print a pattern where each row contains numbers from 1 to the row number.
  10. Generate a checkerboard pattern with alternating 0 and 1.

Try It Yourself

Now that you’ve reviewed the problems, practice them below using the code runner!

1. Square Pattern

PygroundTry It Out

Print a square pattern of * with n rows and columns.

Output:

2. Right-Angled Triangle

PygroundTry It Out

Print a right-angled triangle pattern of *.

Output:

3. Multiplication Table

PygroundTry It Out

Generate a multiplication table up to n.

Output:

4. Pyramid Pattern

PygroundTry It Out

Create a pyramid pattern of numbers.

Output:

5. Number Pattern

PygroundTry It Out

Print a pattern where each row contains consecutive numbers from 1 to row number.

Output:

6. Matrix Sum

PygroundTry It Out

Input a list of lists and calculate the sum of all elements.

Output:

7. Element Pairs

PygroundTry It Out

Print all pairs of elements from two lists.

Output:

8. Matrix Transpose

PygroundTry It Out

Find the transpose of a 2D matrix.

Output:

9. Number Pattern 2

PygroundTry It Out

Print a pattern where each row contains numbers from 1 to the row number.

Output:

10. Checkerboard Pattern

PygroundTry It Out

Generate a checkerboard pattern with alternating 0 and 1.

Output:

Last updated on