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>>

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

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

"Master REGEX in Excel | Boost Your Productivity with These Powerful Tips!"

 "Master REGEX in Excel | Boost Your Productivity with These Powerful Tips!" Regex (Regular expressions), is a tool that finds pat...

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