1. What is looping control flow allowing us to do?
It allows us to run a piece of code multiple times and able to go back to some point in the program where we were before and repeat it with our current program state.
2. Describe what “loops” do in your own words.
Loop allows program to be repeatedly executed based on a set of logic within a certain environment.
3. What is the difference between while and do-loops?
A statement starting with the keyword while
creates a loop.The loop keeps entering that statement as long as the expression produces a value that gives true when converted to Boolean.
let result = 1;
let counter = 0;
while (counter < 10) {
result = result * 2;
counter = counter + 1;
}
console.log(result);
// → 1024
A do
loop is a control structure similar to a while
loop. It differs only on one point: a do loop always executes its body at least once, and it starts testing whether it should stop only after that first execution.
let yourName;
do {
yourName = prompt("Who are you?");
} while (!yourName);
console.log(yourName);
4. What is indentation?
The role of this indentation inside blocks is to make the structure of the code stand out. In code where new blocks are opened inside other blocks, it can become hard to see where one block ends and another begins. With proper indentation, the visual shape of a program corresponds to the shape of the blocks inside it.