1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the two pieces contained in a while loop?
A condition (a boolean expression) and a block (one or more statements).
What is an iteration in the context of loops?
An iteration is a single execution of the loop body.
What does a while loop do when the condition is false?
It skips the block of code inside the loop.
What is the main purpose of sentinel values in looping?
They act as special values to indicate the end of a data set.
What is the difference between pre-test loops and post-test loops?
Pre-test loops check the condition before each iteration (like while loops), while post-test loops check after each iteration (like do-while loops).
What should you typically do within a loop to prevent infinite loops?
Modify the loop condition by changing the variable used in the condition.
What keyword can be used to exit a loop prematurely?
The break keyword.
What is the initializer in a for loop?
It is executed once before the loop starts and is used to initialize a loop control variable.
When should you use a for loop instead of a while loop?
When you know the exact number of iterations beforehand.
What does the increment operator (++) do in loops?
It adds one to the variable and stores the updated value.
How does a do-while loop differ from a while loop?
A do-while loop executes the block at least once before checking the condition.
What is input validation in the context of looping?
It is the process of ensuring that user inputs are valid before proceeding.
What type of loop structure is suitable for reading lines from a file?
A while loop can be used to read each line until the end of the file.
What happens if you attempt to read past the end of a file?
The stream sets its EOF (end-of-file) flag.
In a nested loop, what must you ensure regarding control variables?
Each loop should have separate control variables to avoid conflicts.
What does the .fail() function check for in file streams?
It checks if a prior read operation has failed.
What is the main benefit of using file stream objects?
They allow for input/output operations with files in a similar way to standard input/output.
What does a while loop syntax typically look like?
while (boolean_expression) { // block of statements }.
What happens when you encounter a continue statement in a loop?
It ends the current iteration and returns to the top of the loop.
Why is it important to close file streams after use?
It releases system resources and ensures that all data is written to disk.