1 - The For loop in Python ...
The for loop in Python, allows to execute repeated instructions.Sytax:
for counter in range(start_counter, end_counter):
instructions...
Example. display the first 10 numbers
for i in range (1,11):
print(i)
#prints the first 10 numbers 1, 2, ..., 10
Note
Note that in the loop for i in range(1, n) the last one which is n is not included! This means that the loop stops at order n-1.2- The repetitive structure While
The while structure is used to execute a set of statements as long as a condition is fulfilled and execution stops when the condition is no longer satisfied.Sytax:
while (condition):
intructions ...
Example. display of the first 10 integers with the while loop
i = 1
while(i <= 10):
print (i)
i = i + 1
Younes Derfoufi
No comments:
Post a Comment