File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #Flow control
2+ # 2) Iterative Statement
3+ # loops
4+ #
5+ # for loop
6+ s = input ("Enter a string" )
7+ count = 0
8+ index = 0
9+ for i in s :
10+ print ("the index of {} is" .format (i ),end = " " )
11+ print (index )
12+ index += 1
13+ count += 1
14+ print (count )
15+
16+ l = [10 ,20 ,30 ]
17+ for x in l :
18+ print (x )
19+
20+ for y in range (1 ,10 ):
21+ print (y )
22+
23+ # while loop
24+ # iteration know in advance then we should go for loop
25+ # if we dont know then we can use while loop
26+ # while condition:
27+ # body
28+
29+ # Example 1 print 1 to 10 numbers
30+ x = 1
31+ while x <= 5 :
32+ print (x )
33+ x += 1
34+
35+ #example 2
36+
37+ name = ""
38+ pwd = ""
39+ while (name != 'naveen' ) and (pwd != 1234 ):
40+ name = input ("enter name:" )
41+ pwd = eval (input ("enter password" ))
42+
43+ print ("Hello" ,name ,"Good morning" )
44+
45+ # Example 3 infinite loop
46+ # i = 0
47+ # while True:
48+ # print(i)
49+ # i+=1
50+
51+ #nested loops
52+ #loop inside another loop
53+
54+ for i in range (4 ):
55+ for j in range (4 ):
56+ print (1 ,j )
57+
58+ #example
59+ n = eval (input ("enter number of rows:" ))
60+ for i in range (1 ,n + 1 ): # i represents rows number
61+ for j in range (1 ,i + 1 ): # j represents the number of *
62+ print ("*" ,end = " " )
63+ print ()
You can’t perform that action at this time.
0 commit comments