Practice Nested Loops - 5.5 | Loops – for and while | Python Programming Language
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Nested Loops

5.5 - Nested Loops

Enroll to start learning

You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

What is the output of the following code?

💡 Hint: Count how many times the inner loop runs for each iteration of the outer loop.

Question 2 Easy

Write a simple nested loop to print a triangle of numbers with 3 rows.

💡 Hint: The outer loop controls the rows, and the inner loop controls the columns.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What are nested loops?

💡 Hint: Think about how you work with multi-dimensional data.

Question 2

True or False: The inner loop runs completely for each iteration of the outer loop.

True
False

💡 Hint: Consider what happens with the execution flow in a nested structure.

1 more question available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Write a function that takes a 2D list (matrix) and returns the sum of all its elements using nested loops.

💡 Hint: You will need to initialize a total variable and use nested loops to iterate through each element.

Challenge 2 Hard

Create a pattern output using nested loops to print a right-angled triangle. For size 5, it should look like:

*
**
***
****
*****

💡 Hint: The outer loop controls the rows, and the inner loop will control how many stars to print in each row.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.