<jupyter_start><jupyter_text>Repeat code with while and for loopsIterations, in programmin, allow coders to repeat a set of instructions until a conditon is met. Think about this as being stuck in a loop that will continue until something tells you to break out. While loopThe while loop is one of two iteration types you'll learn about. In this loop you must specify a conditon first and the ninclude the code that you want the loop to iterate over. The loop will first check if the condition is True and if it is then it will look at the code inside the loop. When de condition becomes False, the code in the loop will be skipped over and the program will continue executing the rest of your code. If the condition in the loop is False to begin with, the code within the loop will never execute. During a single loop, the program will hen go through the loop and run the code. Once the code is finished, it will look back at the condition and see if it is still True. It's essential to change the variables in your loop to eventuallly have a condition say that it is False, or else an infinite loop will occur.As shown in the code below, to write a while loop you first must ype "while" and then the condition you'll check before every loop. End the line with a colon and be sure to ident the next line, which will be the actual loop. The code below will print out a countdown for a rocket. As you can see, the countdown variable in the condtiion section decreases in every loop until it reaches -1, in which case the condition is False and the loops ends.<jupyter_code>countdown = 5

while countdown >= 0:
    print(countdown)
    countdown = countdown - 1
print("Lift Off")<jupyter_output>5
4
3
2
1
0
Lift Off<jupyter_text>In the example below, the condition is never met and the loop will contue forever (if we don't stop it). In this code, the developer forgot to decrease the timer variable, so the condition is always true.<jupyter_code># Trying to find life outside our planet
# timer = 10
# while  timer > 0:
#     print("Hello, I am from Earth")<jupyter_output><empty_output><jupyter_text>This is an infinite loop and you must either wait for Python to terminate it or click the stop button at the top of the window. It´s best to avoid infinite loops - if that wasn´t already apparent.  For loopFor loops essentially perform the same task as while loops, they tend to focus on iterating a set number of times. For loops are great when you want to go through a list and look at every single element. In the code below, we make a list and then go through all the elements and print them out.<jupyter_code>planets = "Mars", "Saturn", "Jupiter"

for planet in planets:
    print(planet)<jupyter_output>Mars
Saturn
Jupiter
{'fraction_non_alphanumeric': 0.039222873900293255, 'fraction_numerical': 0.004765395894428153, 'mean_word_length': 4.248076923076923, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '325448', 'license': 'MIT', 'n_tokens_mistral': 716, 'n_tokens_neox': 693, 'n_words': 465, 'path': 'code_control_statements/while_loop.ipynb', 'repo_name': 'Jeffresh/Discover-role-python-space-exploration', 'size': '2728'}