Nested Loop in python

 

Nested Loops

A nested loop is a loop inside a loop.

The "inner loop" will be executed one time for each iteration of the "outer loop":

Nested लूप मे हम एक लूप के अंडर दूसरा लूप चलाते हैं, तो इसमे पहले दूसरा लूप निस्पदित होगा उसके बाद पहला लूप निस्पदित होगा।

Nested while loop:

Example

i = 1
while i < 6:

j = 1

while j < 6:

print(j)
      j += 1
      i += 1

Print each adjective for every fruit:

Example

for x in range(5):
  
for y in range(5):
    
print(x, y)

Example

adj = ["red""big""tasty"]
fruits = [
"apple""banana""cherry"]

for x in adj:
  
for y in fruits:
    
print(x, y)

Output:    Red   apple

            Red   banana

            Red   cherry

            Big   apple

            Big   banana

Big   cherry

            Tasty apple

            Tasty banana

            Tasgy cherry

<<Previous                                                  Next>>

कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

MS Excel to WhatsApp Bulk Message in single Click

Excel to WhatsApp Bulk Message VBA Code File Download VBA Note Pad File - Click here Download Excel Practice File - Click here Copy Code her...

Blogger द्वारा संचालित.