Loops
Are a way of doing the same thing, multiple times.
For loop
For loops have three parts inside their parens
1. Create a variable (called an **iterand** when used in looping, and often named 'i'), and sets it to a value (usually '0')
2. A logical test. **The moment the test returns false, the loop halts**
- This test is run every time before the loop is executed
3. A statement to run when the loop has completed. (Usually adds one to the **iterand**)
The other half of the loop is the block that comes after it. This is the code that is run for every iteration (or loop). In the example above, its everything inside the curly brackets, so we’re just outputting to the console what the value of i is for that loop.
Some others.
While loop
Is just the logical portion of the for loop.
Here’s a while loop, rewritten
Here’s a fun one:
The break statement
Let’s say you did what you need to do in a loop, but its still running.
You can break out of it.