Chapter 2
WHILE AND DO LOOPS
-
What is looping control flow allowing us to do?
-
Describe what âloopsâ do in your own words.
-
What is the difference between while and do-loops?
-
What is indentation?
-
What is looping control flow allowing us to do?
Send us back to the beginning of our program/re-use code multiple times, building on the previously developed state.
- Describe what âloopsâ do in your own words.
Applies the same instructions over and over again on different data sets/and or when the previous loop iteration altered our current state.
- What is the difference between while and do-loops?
While implies we will start a loop. While will continue running the code until a certain parameter is reached.
Let X = Y; While + ( condition to run until X becomes something) { print/do something to the current state; alter the current state of X}
Loop continues to run until the condition turns to false.
Do will continue attempting the loop indefinitely until it gets an initial response. Initial attempt is always made, unlike while statement which required the conditions to be met.
For loops can also be used:
For ( let var = x; continue until x reaches a certain value; do something to x each loop round){console.log(x);}
For â define a binding initialize â check if the loop continues â update the loop.
- What is indentation?
Where you press the tab button and the line indents.
Indentation is not necessarily required; the code will run fine without it. However, it helps with organising structure.