Add link and fix typos. (#23683)
Added missing spaces after periods. Changed "Pyhthon" to "Python". Added a link that leads to more information about lists in Python.
This commit is contained in:
@ -5,7 +5,7 @@ title: For Loop Statements
|
|||||||
|
|
||||||
Python utilizes a for loop to iterate over a list of elements. Unlike C or Java, which use the for loop to change a value in steps and access something such as an array using that value.
|
Python utilizes a for loop to iterate over a list of elements. Unlike C or Java, which use the for loop to change a value in steps and access something such as an array using that value.
|
||||||
|
|
||||||
For loops iterate over collection based data structures like lists, tuples, and dictionaries.
|
For loops iterate over collection based data structures like [lists](https://github.com/freeCodeCamp/freeCodeCamp/tree/master/guide/english/python/lists), tuples, and dictionaries.
|
||||||
|
|
||||||
The basic syntax is:
|
The basic syntax is:
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ for i in range(10):
|
|||||||
print(i)
|
print(i)
|
||||||
```
|
```
|
||||||
Rather than being a function, range is actually an immutable sequence type.
|
Rather than being a function, range is actually an immutable sequence type.
|
||||||
The output will contain results from lower bound i.e 0 to the upper bound i.e 10 but excluding 10.By default the lower bound or the starting index is set to zero.
|
The output will contain results from lower bound i.e 0 to the upper bound i.e 10 but excluding 10. By default the lower bound or the starting index is set to zero.
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ for index, item in enumerate(shopping_basket):
|
|||||||
print("Item", index, "is a", item)
|
print("Item", index, "is a", item)
|
||||||
```
|
```
|
||||||
**for/else statements**
|
**for/else statements**
|
||||||
Pyhton permits you to use else with for loops, the else case is executed when none of the conditions with in the loop body was satisfied. To use the else we have to make use of `break` statement so that we can break out of the loop on a satsfied condition.If we do not break out then the else part will be executed.
|
Python permits you to use else with for loops, the else case is executed when none of the conditions with in the loop body was satisfied. To use the else we have to make use of `break` statement so that we can break out of the loop on a satsfied condition. If we do not break out then the else part will be executed.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
week_days = ['Monday','Tuesday','Wednesday','Thursday','Friday']
|
week_days = ['Monday','Tuesday','Wednesday','Thursday','Friday']
|
||||||
|
Reference in New Issue
Block a user