Jimmy
0
Q:

loops in python

#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
  print(x)
38

  for x in "banana":
  print(x)
 
4
for i in range(1, 10);
	print(i)
2
for x in loop:
	print(x)
6
#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

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

 
3
x = 0
while True: #execute forever
	x = x + 1
	print(x)
1

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

  fruits = ["apple", "banana", "cherry"]
for 
  x in fruits:

	 
	print(x)
 
8

New to Communities?

Join the community