Loops Flashcards

(21 cards)

1
Q

What is a loop?

A

A program that continues to repeat as long as the expression is true.

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

What is another name for a loops statement?

A

Loop body

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

Each time through a loop is known as a?

A

iteration

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

How does a loop start?

A

With a decision statement

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

Does a loop cancel midway if the expression becomes false during the loop?

A

No, the loop finishes

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

When writing loops in a word expression what single operator is used to express “until”

A

!=

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

What is a sentinel value?

A

a special value signaling the end of a list of values.
Example: 13 8 5 0 (0 is the sentinel value)

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

How many parts does an iterating loop have?

A

3

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

What are the 3 parts of an iterating loop in order?

A

1) loop variable initialization
2) loop expression
3) loop variable update

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

explain loop expressions and how many times it will iterate.

A

i < 3 is the loop expressions. The loop will continue until the the expression is 3 which it will then exit the loop.

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

What is a “while loop”?

A

A loop that continues to execute long as it is true.

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

What is a “for loop”?

A

Is similar to a N loop.

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

If the iteration is known before the loop is it best to use a while or for loop?

A

For

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

What is a nested loop?

A

A loop that appears in the body of another loop.

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

How to know how many times an inner (nested) loop will execute?

A

outer loop * inner loop

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

When writing a while loop does the statements following need to be indented or not?

A

They need to be indented because they correlate to the “while loop”

17
Q

When starting/writing a loop statement what “word” signifies/identifies that the loop will continue until the condition is met?

18
Q

what does a do-while loop do?

A

executes the loop body’s statement first, then checks the loops conditions. (this ensures it executes atleast once.)

19
Q

What is a “for loop”?

A

A loop with three parts at the top.
For example: for i = 0; i < 3; i = i + 1

20
Q

In a “for loop” how do you seperate the three parts?

A

With a semi-colon, a semi-colon is not needed at the end.

21
Q

If a iteration is omputable before the loop which type of loop statement should you use if or while?