<jupyter_start><jupyter_text>Lesson 5: Control FlowIn this lesson, we will learn about...+ If...Else statements+ While Loops+ For Loops  If...Else StatementsThese allow us to selectively run parts of a program depending on if a condition is met. Let's look at the anatomy of an if statement.```pythonif CONDITION:    do somethingelif CONDITION:    do another thingelse:    do a third thing``` This corresponds to the following actions in plain English:1. If the first condition is true, "do something", then skip the rest of the if...else2. Otherwise, if the second condition is true, "do another thing", then skip the rest of the if...else3. If none of the above conditions are true, "do a third thing". NOTE: Only the `if` is required. You can leave out `elif` and `else` entirely, and have as many `elif`s as you want. You can only have one `if` and one `else`.<jupyter_code>x = 5
if x % 2 == 0:
    print(x, "is even!")
else:
    print(x, "is odd!")<jupyter_output>5 is odd!<jupyter_text>ConditionsConditions are anything that resolve to either `True` or `False`. They can be...+ Boolean variables+ Boolean Expressions / Comparisons+ Function Calls  Falsy ValuesSome values aren't the literal `False` but still evaluate to be `False`. These are called **falsy**. They are...+ Empty collections (lists, tuples, dictionaries, strings, ...)+ The number 0 in any form+ `None`+ `False`Any other values are considered **truthy** and evaluate to `True`.  Comparisons and Logical OperatorsRecall from Lesson 3 that there are several operators used for comparisons. There are also operators to combine expressions, such as `and` and `or` called logical operators.  LoopsLoops let us run a section of code over and over again. There are two main types of loops in python...+ While Loops+ For Loops  While LoopsThese loops run **while** a condition is true. These conditions are the same as with if statements.<jupyter_code>i = 1
while i < 6:
    print(i)
    i += 1<jupyter_output>1
2
3
4
5<jupyter_text>`break` and `continue`You can use these keywords in a loop to stop the loop (`break`) or skip to the next iteration (`continue`).<jupyter_code>i = 1
while i < 6:
    if i == 3:
        i += 1
        continue
    elif i == 5:
        break
    print(i)
    i += 1<jupyter_output>1
2
4<jupyter_text>For LoopsFor loops are used to iterate over a sequence or finite range (list, tuple, set, string, ...)<jupyter_code>fruits = ["banana", "orange", "strawberry"]

for fruit in fruits:
    print(fruit)<jupyter_output>banana
orange
strawberry<jupyter_text>`range()`The `range()` function generates a sequence of numbers from 0 (by default) to a number with a step of 1 (by default).+ 1 parameter: 0 to $x-1$+ 2 parameters: $x$ to $y-1$+ 3 parameters: $x$ to $y-1$ in increments of $z$<jupyter_code>for x in range(3):
    print(x)
for y in range (1,4):
    print(y)
for z in range (2,10,2):
    print(z)<jupyter_output>2
4
6
8
{'fraction_non_alphanumeric': 0.10147411724374357, 'fraction_numerical': 0.016112444292080905, 'mean_word_length': 4.039723661485319, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '483055', 'license': 'MIT', 'n_tokens_mistral': 939, 'n_tokens_neox': 887, 'n_words': 423, 'path': '05-control_flow/05-control_flow.ipynb', 'repo_name': 'brandoningli/python-tutorial', 'size': '2917'}