Loops - Reading Assignment

Welcome to the discussion about the reading assignment about Loops - Reading Assignment.

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please everything to the topic.

  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?
41 Likes

1-

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 until the requirement is met and then it exits or let program proceed ahead.

2-

Its repetition of a statement (a single thing) until certain criteria is fulfilled or certain requirement is met or certain state is achieved. Its like type 1 and add 1 in previous number and throw result and keep doing it until we reach number 10. And if 10 is thrown then do exit this loop and proceed with the rest of the code. Its a check point where certain task is repeated until desired result, before proceeding.

3-

The difference is in when the condition gets evaluated. In a do loop, the condition is not evaluated until the end of each loop.Do loop will be executed at least once but while loop will check the condition first and then it may or may not get executed depending on the condition.
While loop saves time.

while loop

var number = 0;
while (number <= 12) {
console.log(number);
number = number + 2;
}

do loop

A do loop always executes its body at least once.

var number = 0;
do {
number = number + 2;
console.log(number);
}
while (number <= 10);

4-

Indentation is the increase or decrease of space between the left and right margin (space) of a paragraph or line or statements so that code hierarchy make sense and code becomes more readable.

33 Likes

js-learning

Just a break down of a loop.

70 Likes
  1. What is looping control flow allowing us to do?
  2. Looping control flow allows the program to go back to the start of a conditional execution with the current program state saved in the memory.

  3. Describe what "loops" do in your own words.
  4. This allows the programmer to perform a certain task unitl values are met thus executing a new branch of the program.

  5. What is the difference between while and do-loops?
  6. Given that x is a boolean,

    while (x){y} z;

    the function y is executed only while x is true. Once the boolean condition changes, or if x is false from the original saved state, the looping control flow will execute the next branch of the program z.

    Also,

    do {y} while (x); z;

    In a do loop, y is executed atleast once, and then after the initial execution, the while statement checks for condition x to be false before proceeding to the rest of the progam z.

  7. What is indentation?
  8. Indentations is spaces in the begining of lines of code to make the structure stand out. It is not necessary and only used for readability. A program can be written all in one line since the computer will not read spaces.

8 Likes

1-

it allows us to repeat a task without programming each step of the computation.

2-
it is a repetition of a process until a certain condition/criteria is met

3-
a least the do-loops is executed one time, on the opposite if the condition a the entry of
the while is not met, there will be no execution.

4-

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

4 Likes
  1. What is looping control flow allowing us to do?
    To go back to a point in the program where we created the condition and repeat it.
  2. Describe what “loops” do in your own words.
    To repeat a line of code until the condition is false or reaches a break or return statement
  3. What is the difference between while and do-loops?
    A while loop will run indefinitely until the condition is false. The do part always runs once whether the condition is true or false.
  4. What is indentation?
    It is a tab or several spaces in in front of statements. They don’t affect the program but allows people to read easily to what’s going on.
6 Likes

What is looping control flow allowing us to do?
- Looping control flow allows us to go back to a previous place in the code and repeat it.

Describe what “loops” do in your own words.
- By looping we are able to automate the itteration process, and thus get the computer to perform lots of repetitive work.

What is the difference between while and do-loops?
- While loops first check a condition (i.e. I will do ‘some code’ while ‘B’ is true) then executes code if the condition is true.

	<script>
		
	      var textToDisplay = "Hello!"
	      var a = 8;
	      
	      while(a > 5){
	        document.write("<h2>" + textToDisplay + "</h2>");
	        a--;
	      }
	      
	</script>

- Do loops do first and asks questions later... or ask the conditional while check later.

	<script>

	      var textToDisplay = "Hello!"
	      var a = 8;
	
	      do {
	        document.write("<h2>" + textToDisplay + "</h2>");
	        a--; //decrementing a by 1, a=a-1>
	      } while(a > 5);
  
	</script>

What is indentation?
- These answers are indented to help show clarity between the Question and the Answer. Your code will also read more easily for you where white space is nothing to a computer.

3 Likes

What is looping control flow allowing us to do?
- It allows us to have the program do the counting and keeping track of a value without having to write the code over and over, it reduces the complexity of the code.

Describe what “loops” do in your own words.
- Loops make the program run the code until a certain specified condition is met.

What is the difference between while and do-loops?
- A while loop runs until it reaches a specified value and a do loop runs until it gets any valid input.

What is indentation?
- Indentation keeps the code looking nice and makes it easier to follow when you have to come back and make changes.

  1. What is looping control flow allowing us to do?
  2. Looping control allows us to run a piece of code multiple times.
  3. Describe what "loops" do in your own words.
  4. Loops let the program go back in time to a previous state while retaining knowledge of the state of the loop each time it loops. Like a old CD that skips. Each time it loops maybe a little bit more or less sound is heard.
  5. What is the difference between while and do-loops?
  6. If while was a person it would say, "Hey Mr. Programmer loop this". A do-loop would say, "Hey. Mr.Programmer, loop this but make sure to DO this also".
  7. What is indentation?
  8. indentation is an optional space/linebreak to make the code stand out and give it some structure.
3 Likes
  1. Looping control flow allows us to repeat a set of instructions until specified criteria is met
  2. Loops reduce the size of a program by cycling through a set of code for a specified criteria
  3. do loops will execute the code once before checking the condition of the loop.
  4. Indentation makes the program code cleaner and easier to read/review/troubleshoot. It breaks up the code by indenting code blocks. Using comments to describe code blocks is also beneficial.
  1. it allows us to repeat instructions
  2. repeated cicles of instructions
  3. “do” runs at least 1 time
  4.        This is indentation
  1. Allows the program to execute a part of the program again by resetting the program to the start of the condition.

  2. Code that allows part of the code to be repeated until the base case is reached

  3. while loops execute the program until a condition is reached, do loops are the same except they always execute it at least once.

  4. Spaces at the beginning of lines of code to help the programmer visualize the scope of the code.

1- Looping control allow us to do a repetitive job until a condition is fulfilling

2- Loops execute a block of code while a condition is fulfilling

3- While loops evaluate conditions before execute the content of the loop. Do loops evaluate conditions after the block of the loop is executed at least once

4- Indentation is spacing the code from the margin when it’s inside a block for making the code more readable

1 Like
  1. Looping Control Flow allow us to execute a block of code a number of times.
  2. Loop is created when a block of code executed a number of times.
  3. In while loop condition is validated up front before execution of the loop block but in do-loops, loop block is executed at least once.
  4. Indentation makes code more readable and structured.
1 Like
  1. Go back to a certain point in the program and repeat that part of the program again
  2. Run code for a wanted number of times.
  3. A do-loop has to run at least one time, a while-loop first checks whether a statement is true or false
  4. It’s a way to structure blocks of code and make it stand out more
1 Like
  1. A looping control flow allows us to run a piece of code multiple times by jumping back to some point in the program.
  2. Loops repeat a certain collection of statements multiple times, as long as a certain condition expression yields true.
  3. while-loops test the looping condition before the first execution of the loop body, do-loops on the other hand execute the looping body once before the looping condition is checked.
  4. Indentation describes the adding of spaces or tabs before the actual statements. While indentation is technically not needed, it is used inside of new blocks to visually show the structure of the program.

What is looping control flow allowing us to do?
Allows us to go back to some point in the program where we were before and repeat it with our current program state

Describe what “loops” do in your own words.
Loops is a process in a statement that repeats execution until false or a statement called break is inputted

What is the difference between while and do-loops?
While creates the loop and in the statement the loop keeps entering.
A do loop is like a while loop but it’s different in one way which it executes its body at least once and only after does it decide to stop

What is indentation?
Indentation is to structure your code to be more readable and is also a matter of reference

What is looping control flow allowing us to do?

It allows us to go back to a previous point in the program and repeat it with our current program state

Describe what “loops” do in your own words.

Loops allow you to make your code more simple and elegant by reusing a certain section multiple times.
What is the difference between while and do-loops?

A do loop always executes its body at least once. A do loop has it’s test after the body of the loop and a while has it’s test at the beginning

What is indentation?

Indentations make the structure of the code stand out and allow you to clearly differentiate one section from another

What is looping control flow allowing us to do?

It allows us to repeat a group of statements multiple time until a defined condition is reached.

Describe what “loops” do in your own words.

Loops are code constructs that allow us to repeat different operations multiple times unitl a condition is achieved.

What is the difference between while and do-loops?

A while will check the condition first before executing the associated code, if the condition is false no code is executed.
Do will execute the code at least once then check the condition for the loop

What is indentation?

It is cosmetic spacing at the start of the line to clearly show which code portions belong to which construct such as loops.

1. What is looping control flow allowing us to do?
Allows programs to repeat a set of instructions (code statements) located inside the loop block as long as a specified condition is true. 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.
If the loop expression evaluates to true a loop will execute the loop block. Once done executing the loop block the loop expression is evaluated again and will keep iterating (looping) thereby executing the loop bock code as long as the expression remains true. When the expression is false the loop stops and the program continues executing the code that follows the loop code.

3. What is the difference between while and do-loops?
While loops may execute the loop block statements zero times or more. Do-loops will always execute the loop block statements at least once and they are the only bottom-checking loop, that is that they check if the expression is true at the bottom of the loop after executing the loop block statements.

4. What is indentation?
Indentation is used to display the structure of the code as blocks of code and make it easier to read your own code and for your colleagues to read and update or add to your code in a collaborative project. 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.

2 Likes