1. What is looping control flow allowing us to do?
It allows an executing program to go back to an earlier point in the program to run a piece of code multiple times. Generally the loop will slightly modify the input upon execution as to break its initial condition; once the initial condition is broken, the program will consider the “loop” complete and move on by executing the next statement in the flow.
This whole process allows us as programers to simplify the amount of work we would’ve otherwise had to do. For example, a program that is supposed to print the numbers 1-1000 on the console would take forever to type out by hand in 1000 independent lines, but if we set up a loop, then the tedious process becomes very simple and quick.
2. Describe what “loops” do in your own words.
Answer in 1st paragraph above.
3. What is the difference between while and do-loops?
While loops check the initial condition before proceeding to execute the code within the loop’s body.
Do-loops always complete the code in the body BEFORE checking any conditions. This makes it so that the do loop will ALWAYS execute the body AT LEAST ONCE.
4. What is indentation?
Indentation is spacing added to code to make it more readable. These extra spaces do absolutely NOTHING as far as functionality or execution are concerned. They just make each block of code take a uniform visual shape if done correctly, which allows the code easier to read through later. I will be using the “TAB” key every time a new of code is created.
For example, if I have an “if” statement containing a nested “if” statement, then I would first indent (1 TAB) all the code written in the BODY of the initial “if” statement…leaving the opening line declaring the if statement and it’s condition alone. The 2nd “if” statement nested within the first would be declared with a single indent (1 TAB) because it is the declaratory line of a new block. Then I would double indent (2 TAB) the body of the 2nd “if” statement to visually separate the 2 blocks of code from one another making it easier to read.