Chapter 5 Flashcards

(25 cards)

1
Q

What is the general form of the while loop?

A

while(expression){
statement
}

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

While is a reserved word true or false?

A

True?

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

A while expression can be either:

A

Compound or Simple

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

What does the expression in a while loop act as:

A

The decision-maker

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

Expressions are usually a ______ expression?

A

Logical

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

What is the usually body of the loop?

A

The statement

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

What does the expression provide?

A

Entry condition to the loop

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

How does the while loop work?

A

If the statement evaluates to true the program loop until the program evaluates to false.

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

What is an infinite loop?

A

A loop that runs endlessly

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

How do you avoid infinite loops?

A

Make sure your loop’s body contains statements that assure the expression will become false.

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

What is an LCV?

A

Loop control variable.

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

Where is the LCV initialized?

A
before the while loop:
//initialize the LCV
while(expression){ //expression test the LCV
statement  // update the LCV
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a counter controlled while loop?

A

A while loop used when you know how many items of data are to be read. The loop will continue until the condition is met or is false.

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

Counter controlled while loop looks like:

A

counter = 0; // LCV
while(counter < N) { //expression test the LCV
counter ++; // update the LCV
}

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

What is a case sentinel loop used for?

A

When we are unaware of how much data will be read in.

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

What is a case sentinel loop look like?

A

cin&raquo_space; variable; // LCV
while (variable != sentinel) {
cin&raquo_space; variable; // update
}

17
Q

What is a flag controlled while loop?

A
A flag controlled while loop uses a boolean variable to control the execution of the loop:
isFound = false;
while(! isFound) {
if( expression)
isFound = true;
}
18
Q

What does EOF mean?

19
Q

What is an EOF controlled while loop mean?

A

Is a while loop that stops when it reached the end of an input file.

20
Q

What is the first way that a stream variable can return a value after reading data?

A

If the program has reached the end of the input stream variable returns the logical value false.

21
Q

What is the second way that a stream variable can return a value after reading data?

A

It program read faulty data (like a char to an int variable) the input stream enters a fail state a fail state. After this happens any further I/O operations are null. However, the computer does not stop the program or throw any errors. The variable return false.

22
Q

What is the third way that a stream variable can return a value after reading data?

A

In case one and two the input stream can return true.

23
Q

What is the C++ function that you can use with an input stream variable to determine end of file status?

A

EOF function:

istreamVar.eof() (it works best for text files)

24
Q

What is a for loop?

A

A specialized form of the while loop. Its purpose is to simplify the writing of counter controlled loop.

25
What does the for loop look like?
for(initial statement, loop condition, update statement) | for( i=0, i < 10, i++)