<jupyter_start><jupyter_text>For Statement Iteration is a key to success in programming. Perhaps, it's the very reason the computer was even concepted. Most are familiar with the uses of a for-statement, and nothing changes semantically in Python. Syntax differs, but use cases are the same. Let's take a look! The for statement is used for iteration. We can do the same task multiple times with a single for statement. There are many varying syntaxes, and we will look at all of them. Let's look at the basics:    for item in domain:        // codeFor loops typically **iterate over** elements in a domain. These elements can be any type as item takes on the value of each consecutive value of the domain. A domain can be a data structure like a list, tuple, dictionary, etc., it could be a range of numbers. In specific, it is anything that is of type **Iterable**. Let's look at a few examples of using the for statement. **Example 1** A natural example is to assume that we have a list of objects. Let's say we have a list of names, and we want to print all of them. We could seperately access each one.. that's too slow.. we put 2 and 2 together and decide to use a for statement.<jupyter_code>names = ["Harry", "Joanna", "Micah", "Robertson"]

for name in names:
    print(name)<jupyter_output>Harry
Joanna
Micah
Robertson<jupyter_text>Let's think as to how it worked. We provided a list of 4 names. We specified the syntax as    for item in domain:        print(item)        where our item was a name, and domain was the list of names. We printed the name, and each time the loop ran it went to the next name until it hit "Robertson" and ran out of names to go to. **Example 2** We can emulate the process with a tuple, too. Let's test it out. Here, we've inserted a movie name, the cost to go to the movie at the time, and the box office earnings in the first 24 hours.<jupyter_code>my_tup = ("Rocky", 19.0, 3400403)
for value in my_tup:
    print(value, end=" ")<jupyter_output>Rocky 19.0 3400403<jupyter_text>We iterated over the 3 values (movie name, cost, box office) by letting our variable "value" take on the identity of each object, and then get printed without making a newline character ("\n"). **Example 3** Iterating over dictionaries works, too. Let's print the stock count for a few employees at a startup.<jupyter_code>stock_dict = {"Micah":20, "Loanthony":31, "Fofo":12}
for person in stock_dict:
    print("Person: {x}   Stocks: {y}".format(x=person,y=stock_dict[person]))<jupyter_output>Person: Loanthony   Stocks: 31
Person: Micah   Stocks: 20
Person: Fofo   Stocks: 12<jupyter_text>Python has a range() function. Range simply allows us to specify a number range like this:        range(inclusive, exclusive)    Where, in a for loop, the item variable takes on every value from the incusive up until the exclusive number.<jupyter_code># Ranges start from 0 at default
for num in range(8):
    odd_or_even = None
    if num % 2 == 0:
        odd_or_even = "Even"
    else:
        odd_or_even = "Odd"
    print("{x} is {y}".format(x=num, y=odd_or_even))<jupyter_output>0 is Even
1 is Odd
2 is Even
3 is Odd
4 is Even
5 is Odd
6 is Even
7 is Odd
{'fraction_non_alphanumeric': 0.0750788643533123, 'fraction_numerical': 0.016719242902208203, 'mean_word_length': 3.978021978021978, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 13, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '449701', 'license': 'MIT', 'n_tokens_mistral': 985, 'n_tokens_neox': 921, 'n_words': 498, 'path': 'Control Flow/for-statement.ipynb', 'repo_name': 'mohsinhaider/pythonbootcampacm', 'size': '3170'}