Andrew T.
0
Q:

how to make loops in python

#While Loop:
while ("condition that if true the loop continues"):
  #Do whatever you want here
else: #If the while loop reaches the end do the things inside here
  #Do whatever you want here

#For Loop:
for x in range("how many times you want to run"):
  #Do whatever you want here
5
#simple for loop to print numbers 1-99 inclusive
for i in range(1,100):
  print(i)
  
#simple for loop to loop through a list
fruits = ["apple","peach","banana"]
for fruit in fruits:
  print(fruit)
1
x = 0
while True: #execute forever
	x = x + 1
	print(x)
1
for x in range(0, 3):
    print("We're on time %d" % (x))
0
for i in range(0, 10):
  #do stuff
  pass
0

New to Communities?

Join the community