#the number is how many times you want to loop
for i in range (number):
#here where you put your looping code
#for example
for i in range (4):
print(Hello World)
print(Hi World)
#output
Hello World
Hi World
Hello World
Hi World
Hello World
Hi World
Hello World
Hi World
#check out more:https://www.askpython.com
# a 'while' loop runs until the condition is broken
a = "apple"
while a == "apple":
a = "banana" # breaks loop as 'a' no longer equals 'apple'
# a 'for' loop runs for the given number of iterations...
for i in range(10):
print(i) # will print 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
# ... or through a sequence
array = [3, 6, 8, 2, 1]
for number in array:
print(number) # will print 3, 6, 8, 2, 1
for _ in range(1,10,2): #(initial,final but not included, gap) (the "_" underscore symbol mean there are no variables initialize in this loop)
print("hi");
# There are 2 types of loops in python
# while loops and for loops
# a while loops continues for an indefinite amount of time
# until a condition is met:
x = 0
y = 3
while x < y:
print(x)
x = x + 1
>>> 0
>>> 1
>>> 2
# The number of iterations (loops) that the while loop above
# performs is dependent on the value of y and can therefore change
######################################################################
# below is the equivalent for loop:
for i in range(0, 3):
print(i)
>>> 0
>>> 1
>>> 2
# The for loop above is a definite loop which means that it will always
# loop three times (because of the range I have set)
# notice that the loop begins at 0 and goes up to one less than 3.
def take_inputs2():
stop_word = 'stop'
data = None
inputs = []
while data != stop_word:
data = raw_input('please enter something')
inputs.append(data)
print inputs