Loops - Reading Assignment

  1. What is looping control flow allowing us to do?

Looping control flow allows code to execute vertically top to bottom, left to right and if conditions for that loop have not been met to close, that control flow circles back around to the top of the code.

  1. Describe what “loops” do in your own words.

Loops allow code to compute and execute indefinitely until the parameters of stopping that code are met. This makes it possible to have a reoccurring statement for calculations that would be too long or time-consuming for us to calculate on our own.

  1. What is the difference between while and do-loops?

A while loop executes continues to execute until the parameters have been met for the code to stop. Do loops are similar but, they examine the code and if they can stop executing, they will at the first chance they get.

  1. What is indentation?

Indentation is an aesthetic presentation of the code to appear easier to understand. Blocks are indented and create sort of trees of data.

1 Like
  1. It allows us to go back to some point in the program where we were before and repeat it with our current program state.

  2. They keep eliminating conditions until it finds the right condition then executes and ends.

3.The do loop always executes its body at least once and starts testing only after the first execution.

  1. It is to make the structure of the code stand out therefore easier to see where new blocks are opened in other bolcks.
1 Like

Hi @Kraken!

Questions 1 and 3 :+1:

…it’s actually the opposite:   loops keep repeating the task while the condition still evaluates to true (i.e. the condition is met)
until
the condition evaluates to false (i.e. the condition fails).
But maybe that’s what you meant, but just conceptualise it in the opposite way, which is fine.

Yes… if what you mean by a block is a statement within a “parent”, starting on a new line and more to the right… which isn’t the same as a code block (a group of statements within curly braces).

1 Like

Hi @pascaldeb!

Good answers! :ok_hand:

You could clarify this a bit more by saying something like:
…it always executes this part of the program at least once, because the condition is tested after the loop, rather than before.

1 Like
  1. What is looping control flow allowing us to do?
    A way to run a piece of code multiple times. This form of control flow is called a loop.Looping
  2. Describe what “loops” do in your own words.
    It repeats the code
  3. What is the difference between while and do-loops?
    do loop always executes its body at least once, and it starts testing
    whether it should stop only after that first execution.
  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.
1 Like

1- Looping control flow allows us to execute a statement and then come back to the start of that statement to start the process again without re-writing the code.
2- Loops take a statement and executes over and over until a certain condition is met.
3- Do loops will always execute a statement in the loop body at least once where as a while loop wont repeat unless its boolean condition reads false
4- Indentation is simply used to structure code to help read and distinguish between statements.

1 Like
  1. Looping control flow allows us to go back to some previous point in the program and repeat it with our
    current program state.
  2. Control flow running of a piece of code multiple times.
  3. A do loop always executes its body at least once, and it starts testing whether it should stop only
    after that first execution.
  4. Indentation is used inside blocks to make the structure of the code stand out.
1 Like
  1. What is looping control flow allowing us to do?
    Allow us to go back to some point in the program where we were before and repeat the action.

  2. Describe what “loops” do in your own words.
    It keeps going around the task till it reaches its goal to end the task.

  3. What is the difference between while and do-loops?
    While and do loop achieve the same task but they differ, a do loop always execute its task at least once.

  4. What is indentation?
    Stands out the code block

1 Like
  1. It allow us to execute the same code a multiple times automatically without typing same commands every time.
  2. Loops lets a program to perform the same action multiple times until conditions described in function are met.
  3. They are basically the same, but do loop is going to be performed at least one time even condition are met, while at the same time, if while condition are met it will skip the loop and continues the program.
  4. Indentation is the order or the way how programer assembles the code (using new lines and spaces), making it visually understandable, attractive or ,lets say, sexy for a human eye. :slight_smile:
1 Like

Hey guys,

I’ve been using the examples from the book and I’ve been experimenting will what can be done. I want to this “switch” block to loop and prompt the user to enter an answer again if the “console.log” logs “Unknown weather type!”. I’ve tried many different ways, but haven’t been successful. Here’s the closest I’ve coming to something that works:

let j = “rainy”
let g = “sunny”
let s = “cloudy”

do {switch (prompt(“what’s the weather like”)){
case “rainy”:
alert(“Damn stay indoors.”);
break;
case “sunny”:
alert(“Dress lightly.”);
case “cloudy”:
alert(“Go outside.”);
break;
default:
alert(“Unknown weather type!”);
}
} while (!j,!g,!s);

Please help!

Thank you :slight_smile:

1 Like
  1. What is looping control flow allowing us to do?
  • It allows us to repeat tasks again and again until a particular condition is met within the code
  1. Describe what “loops” do in your own words.
  • They will repeat a coded instruction over and over until a particular condition is met
  1. What is the difference between while and do-loops?
  • While loops will continue to execute over and over only when the condition is True
  • do-loops will check after running once if they need to run again
  1. What is indentation?
  • Although not necessary for the program to run it is good to use indentation in order for your code or blocks of code to stand out. the important thing to remember is that each new block adds the same amount of space
2 Likes
  1. Loops allow the control flow to repeat a task as many times as needed until a condition is met.
  2. Loops repeat a statement as long as a condition in the function holds up as true.
  3. While functions look for a condition to be met. As long as the condition is met in can repeat an associated statement. Do While loops first execute the block of code once and then checks if the condition is met. It can then loop indefinitely while the condition returns true. In other words, it could be expressed as, “Do this first, then repeat until what we´re checking for is false.”
  4. Indentation is used to make blocks of code easier to read.
1 Like
  1. What is looping control flow allowing us to do?
    It allows the program to repeat the code until the conditions are met.
  2. Describe what “loops” do in your own words.
    Loops are used to re-iterate lines of code, until the conditions have been satisfied to exit out of the loop.
  3. What is the difference between while and do-loops?
    while loops execute lines of code until the condition is false, whilst a do-loop execute lines of code before checking the conditions of the loop.
  4. What is indentation?
    It is a way of alining the lines of code, in order to make the program cleaner and systematical. “tab” is used to make indents easier, or you can use “space” to manually manage the spacing of each indentation.
1 Like
  1. Looping control flow allows us to return to a previous part in the program, with our current (updated) state.
  2. A loop consolidates multiple repetitive statements into one. It repeats a piece of program multiple times.
  3. A ‘while’ loops starts examining if it should stop immediately (from 0), whereas a ‘do’ loop only stats examining if it should stop after the first execution.
  4. Indentation is the practice of spacing and giving structure to code. Without spacing, a program would be very difficult to read and statements would be difficult to distinguish from one another.
1 Like

A: A way to run a piece of code multiple times and allows you to go back to some point in the program where we were before and repeat it with our current program state

A: loops are a way to constantly repeat a function many times without having to keep going back to the function and rewriting the function every time

A: Loops repeat the same functions and while is a way to direct which direction the next function will go to next

A: The role of this indentation inside blocks is to make the structure of the
code stand out

  1. What is looping control flow allowing us to do? Looping control flow allows us 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. Basically they give instruction to repeat a certain action a number of times
  3. What is the difference between while and do-loops? A do loop tests the end of execution every time is executed, a while has a programmed number of repetitions
  4. What is indentation? Is used to keep order in the written code by using proper spaces and it is useful in shared works.
1 Like

Hi, @AF90,

Yes :+1: … and I think you also need to add to your explanation something about how the loop “decides” how many times to repeat before exiting, as this is key.

Loops contain a Boolean expression which checks whether the value assigned to an iterator variable — which acts like a counter — meets a specific condition . If this condition is met, the expression evaluates to true and the loop’s code block is executed. If the Boolean expression evaluates to false then the loop is exited.

2 Likes

Hi @Mesiah,

Q1 & Q4 :+1:

I think you also need to add to your explanation something about how the loop “decides” how many times to repeat before exiting, as this is key.
Have a look at this post if you’re not sure what I mean.

I think you’re a little confused here. Loops are not functions, they are types of statements which direct the program’s direction based on a condition. In this sense they are like if...else statements, although they direct control flow differently (repeating instead of “branching”)

While loops start by evaluating the condition before executing their code block for the first time. This means that, if the condition is not met from the outset, the loop’s code block will be omitted completely.
In contrast, the condition in do loops is placed after the code block. This means that the code block will always be executed at least once before the loop is exited.

I hope that makes things a little clearer. :smiley:

1 Like

Ok I will go back thanks for the input

2 Likes
  1. What is looping control flow allowing us to do?
  2. Describe what “loops” do in your own words.
  3. What is the difference between while and do-loops?
  4. What is indentation?

A. Looping Control Flow allows programs to execute actions back and forth upon satisfied certain specific conditions saved in the memory.

B. A Loop is a repetition of a processes until a satisfied certain specific conditions saved in the memory is no longer true or become false or unsatisfied.

C. Both while loops and do- while loops are loops but the difference is do - loop execute the once without any condition before it actually enters the loop.

D. Indentation are spaces between each lines of code which make the code easier to view clearly and readable for understanding. The role of indentation inside blocks is to make the structure of the code stand out.

1 Like