Loops - Reading Assignment

  1. Looping control flow allows us to design conditional code that interrupts the logical top down flow and executes Code based on values in the program.
  2. Loops allow repetitive iterations of code.
  3. WHILE loops execute WHILE a condition is true (ie - c < 10) DO loops execute at least once, then check for true or false, conditioning the second pass.
  4. Indentation is a practice of vertically lining up loops of code so that they “nest” inside each other in the code. Indentation creates a more readable program.

  1. What is looping control flow allowing us to do?
    Run a piece of code over and over again.
  2. Describe what loops do in your own words.
    Allow us to repeat code until a condition is met. To control types of input by the user. To repeat a process a variable amount of times.
  3. What is the difference between while and do loops?
    Do loops preform the output at least once… while loops check the criteria before the first run.
  4. What is indentation?
    Part of the visual formatting of your code that makes it easier to read.


  1. Looping control flow allows us to manipulate the execution order of a program, so instead of going from top to bottom it may go to another point.
  2. Loops repeat an operation until a condition is reached, in which case the loop is exited.
  3. While loops check for a condition and execute the loop until that condition is reached. If the condition is true on the initial run, the loop will not be executed. Do-loops complete the action at least one time before checking if a condition is true.
  4. Indention helps with readability to the programmer of different segments of the program. It does not affect the execution of the program.

  1. Looping control flow allows us to iterate over a data structure multiple times

  2. Loops allow a programmer to loop through a data structure multiple times in order to update the behaviour of the program/application when the data within the structure meets a specific condition.

  3. A programmer should use while loops to iterate over a data structure when it is unknown how many times the loop needs to be executed whereas they should use a do while loop if they know that it must be executed at least once!

  4. Indentation is used to basically make a program readable. The conventions vary a little but basically the procedure is that when you create a new function or loop, you indent the block inside that function/loop body a certain number of spaces e.g. typically 2 or 4 spaces

function myMainFxn() {
  // indent 2 spaces on body of function
  const data = [1, 2, 3, 4];

  for (i = 0; i < data.length(); i++) {
    // indent 2 spaces again on function body
    // do something data is certain value e..t.c