Chapter 5 Flashcards
(25 cards)
What is the general form of the while loop?
while(expression){
statement
}
While is a reserved word true or false?
True?
A while expression can be either:
Compound or Simple
What does the expression in a while loop act as:
The decision-maker
Expressions are usually a ______ expression?
Logical
What is the usually body of the loop?
The statement
What does the expression provide?
Entry condition to the loop
How does the while loop work?
If the statement evaluates to true the program loop until the program evaluates to false.
What is an infinite loop?
A loop that runs endlessly
How do you avoid infinite loops?
Make sure your loop’s body contains statements that assure the expression will become false.
What is an LCV?
Loop control variable.
Where is the LCV initialized?
before the while loop: //initialize the LCV while(expression){ //expression test the LCV statement // update the LCV }
What is a counter controlled while loop?
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.
Counter controlled while loop looks like:
counter = 0; // LCV
while(counter < N) { //expression test the LCV
counter ++; // update the LCV
}
What is a case sentinel loop used for?
When we are unaware of how much data will be read in.
What is a case sentinel loop look like?
cin»_space; variable; // LCV
while (variable != sentinel) {
cin»_space; variable; // update
}
What is a flag controlled while loop?
A flag controlled while loop uses a boolean variable to control the execution of the loop: isFound = false; while(! isFound) { if( expression) isFound = true; }
What does EOF mean?
End of file?
What is an EOF controlled while loop mean?
Is a while loop that stops when it reached the end of an input file.
What is the first way that a stream variable can return a value after reading data?
If the program has reached the end of the input stream variable returns the logical value false.
What is the second way that a stream variable can return a value after reading data?
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.
What is the third way that a stream variable can return a value after reading data?
In case one and two the input stream can return true.
What is the C++ function that you can use with an input stream variable to determine end of file status?
EOF function:
istreamVar.eof() (it works best for text files)
What is a for loop?
A specialized form of the while loop. Its purpose is to simplify the writing of counter controlled loop.