Posts

Showing posts with the label nested loop

16.Nested Loops

A nested loop is a loop inside another loop.The "inner loop" will be executed completely for each iteration of the "outer loop": we can nest while loops, for loops or the combination. Syntax The syntax for a nested while loop statement in Python programming language is as follows    while expression:        while expression:             statement(s)         statement(s)   The syntax for a nested for loop statement in Python programming language is as follows  for iterating_var in sequence:      for iterating_var in sequence:           statements(s)       statements(s)  Note: indentation is very important to identify the code blocks Example: i=1 while i<=3:    j=1    while j<=i:       print(j,end=' ')            # inner ...