Different Ways To Iterate Through Range Of Values

Iteration is the process of moving through or performing an action within a number of specified times. (Credit: Bestbrain)

In Python programming, iteration is very important. There are different ways of iteration, either through the use of conditions of lists

The following are ways of iterations;

1. Through the use of the 'for' conditional statement. E.g
We are to output the name Brainy for 10 times
We first assign 10 to a variable or do the operation straight away.

Times = 10
For i in range(Times):
    Print ('Brainy')
Or
For i in range (10):
   Print ('Brainy')

2. Through the use of the while conditional statement. For the while condition, we will first assign 10 to the variable before performing the action

Times = 10
while Time <=10:
   Print ('Brainy')
   Time+1

3. The use of the list
For example
['Brainy' for i in range (10)]

Thanks for reading. All your comments are welcomed

No comments:

Post a Comment