Javascript Syntax: Loops Flashcards

1
Q

While Loop

A

The while loop creates a loop that is executed as long as a specified condition evaluates to true. The loop will continue to run until the condition evaluates to false. The condition is specified before the loop, and usually, some variable is incremented or altered in the while loop body to determine when the loop should stop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Reverse Loop

A

A for loop can iterate “in reverse” by initializing the loop variable to the starting value, testing for when the variable hits the ending value, and decrementing (subtracting from) the loop variable at each iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Do…While Statement

A

A do…while statement creates a loop that executes a block of code once, checks if a condition is true, and then repeats the loop as long as the condition is true. They are used when you want the code to always execute at least once. The loop ends when the condition evaluates to false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For Loop

A

A for loop declares looping instructions, with three important pieces of information separated by semicolons ;:

The initialization defines where to begin the loop by declaring (or referencing) the iterator variable
The stopping condition determines when to stop looping (when the expression evaluates to false)
The iteration statement updates the iterator each time the loop is completed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Looping Through Arrays

A

An array’s length can be evaluated with the .length property. This is extremely helpful for looping through arrays, as the .length of the array can be used as the stopping condition in the loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Break Keyword

A

Within a loop, the break keyword may be used to exit the loop immediately, continuing execution after the loop body.

Here, the break keyword is used to exit the loop when i is greater than 5.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Nested For Loop

A

A nested for loop is when a for loop runs inside another for loop.

The inner loop will run all its iterations for each iteration of the outer loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Loops

A

A loop is a programming tool that is used to repeat a set of instructions. Iterate is a generic term that means “to repeat” in the context of loops. A loop will continue to iterate until a specified condition, commonly known as a stopping condition, is met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly