Skip to content

Commit 447eb22

Browse files
authored
clarify some details of for loops
1 parent c87fe89 commit 447eb22

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: _episodes/01-introduction.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ for variable in list:
279279
```
280280
{: .language-python}
281281
282-
Indentation is very important in python. There is nothing like an `end` or `exit` statement that tells you that you are finished with the loop. The indentation shows you what statements are in the loop. Each indentation is 4 spaces by convention in Python 3. Let's use a loop to change all of our energies in kcal to kJ.
282+
There are two very important pieces of syntax for the `for` loop. Notice the colon `:` after the word list. You will always have a colon at the end of a `for` statement. If you forget the colon, you will get an error when you try to run your code.
283+
284+
The second thing to notice is that the lines of code under the `for` loop (the things you want to do several times) are indented. Indentation is very important in python. There is nothing like an `end` or `exit` statement that tells you that you are finished with the loop. The indentation shows you what statements are in the loop. Each indentation is 4 spaces by convention in Python 3. However, if you are using an editor which understands Python, it will do the correct indentation for you when you press the tab key on your keyboard. In fact, the Jupyter notebook will notice that you used a colon (`:`) in the previous line, and will indent for you (so you will not need to press tab).
285+
286+
Let's use a loop to change all of our energies in kcal to kJ.
283287
```
284288
for number in energy_kcal:
285289
kJ = number * 4.184

0 commit comments

Comments
 (0)