0
Q:

python loop

#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
  print(x)
38
n = 4
for i in range(0, n): 
    print(i) 
8

  for x in "banana":
  print(x)
 
4
for i in range(1, 10);
	print(i)
2
for x in loop:
	print(x)
6
a_list = [1,2,3,4,5]

#this loops through each element in the list and sets it equal to x
for x in a_list:
	print(x)
1
#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

  fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)
  
  if x == 
  "banana":
    break

 
3
for index in range(len(list)): 
    print list[index]
5

  fruits = ["apple", "banana", "cherry"]
for x in fruits:
  if x == 
  "banana":
    continue
  print(x)
 
1

New to Communities?

Join the community