Python - Part #3
What is a loop and why do we use it? A loop is a repetition of a process that is iterated over and over as long as the condition is true or until it is intentionally broken. It is highly useful because it massively reduces the repetition of the code and increases its efficiency. Note: The hash " # " represents the comments which do not alter the code. WHILE LOOPS: Example: x = 1 # Variable declaration while x <= 5: print(x) x += 1 Because 1 is less than 5, my boolean condition is true, or in other words: as long as 1 is less than 5 run the program, however, I am adding one to the number each time the program is repeated, so it will automatically stop as soon as the boolean condition is not true anymore. Output: >> 1 >> 2 >> 3 ...