-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loops.py
50 lines (38 loc) · 1.77 KB
/
Loops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Loops is very importent role in coding
inital =0
#while inital>10 :
#print("yes") #nothing will happen because "0 can never bigger than 10"
#but if we reverse the condition "initial<10" than infinity loop will start which never stop
# to stop that loop on somewhere you have to provide some case or condition to it
#like
while inital<10 :
print("yes" + str(inital)) #now "yes" print 5 time than loop stop becasue after that initial become bigger than 10
inital=inital+2
#More exmples
#print counting unitl 50
i=1
while i<=50:
print(i)
i=i+1
#print list with while loop
l1=["Raju","Sonu","Deepti","Sonia","Kunal"]
i=0
while i<len(l1):
print(l1[i])
i=i+1 # is question comes in your mind why we wrote every time "i=i+1". "Nahi!" toh lao thodi "ruchi" lao isme...
# if you not give the increment in value than how you will come out from loop. because if value is true than it never will stop
# fir ant-man ki traha quantum face mein attk jaoge.
# to come out from loop hume value ko badna hai ta jo hmari conditon false ho or hmari jann chutte isse.
# For loop syntac with example:
#
Table=[1,2,3,4,6,8]
for item in Table: #"item" help us to do work in one-shot
print(item) #mujhe pta hai khoge yeh bhbut asan tha yr "while" to kafi tedda hai
#try to print "li" list which is on line number 23.
for item in l1:
print(item) #yeh kya sirf ek line k code me hogya or while mein teen line baap re! "Raju" dekh re baba kya zhol ho rha hai idder!
#Range function in Python
for i in range (8):
print(i) # you will get number from 0 to 7. length is total eight but counting only till seven beacause in coding it will start from 0 if you provide any start point
# basic on range function from example come to "RangeFunction.py" file.
#