Python Nested Loop

Iteration is used to repeat some actions a number of times. In Python is called nested loop the following example and syntax of nested loop

Syntax

							
while test expression:
	body of main while
	while test expression
		body of inner loop
	
							
							

Example

							
matrix = [ [5,4,7,11],[3,3,8,17] ]
i=0
while i < len(matrix):
    j=0
    while j < len(matrix[i]):
        print matrix[i][j]
        j=j+1
    i=i+1				
							
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!