Looping Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

for loops

A

FOR loop. This type of loop requires a variable that counts how many times the computer
repeats the same set of instructions and then stops after the indicated number of loops. These looping
structures look different in different languages, but follow the same principle. In JavaScript, it looks like this:

for (var counter = 0; counter < 11; counter++)
{
…instructions…
}

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

while loops

A

This is usually called a WHILE loop. The
instructions inside the loop will be run repeatedly until the condition becomes false, so be sure that the
instructions do not create an infinite loop. These looping structures look different in different languages,
but follow the same principle. In JavaScript, it looks like this:

while (condition)
{
…instructions…
}

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

do-while loops

A

do
{
if (input != “Q”
{
}

}
while(input != “Q”

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

sentinel values

A

a special value in the context of an algorithm which uses its presence as a condition of termination,

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

infinite loops

A

A loop a continues forever.

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

loop counters

A

a variable that counts up

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

Break

A

The break command causes an immediate exit out of the loop, while the continue
command skips over all other instructions inside the loop structure but iterates the loop counter and
returns to the beginning of the loop again.

while (condition)
{
if (…)
{
break;
}
…instructions…
}

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