NEW
Font size
WorksheetsVisual C# Quiz - Chapter 5: Loops, Files, and Random Numbers
Total questions: 15
Worksheet time: 11mins
What does a while loop do?
Does not execute any statements
Repeats a statement until a Boolean expression is true
Executes a statement only once
Repeats a statement as long as a Boolean expression is true
What is the structure of a while loop?
if (BooleanExpression) { statements }
do { statements } while (BooleanExpression)
for (Initialization; Test; Update) { statements }
while (BooleanExpression) { statements }
What type of loop is a while loop considered?
Pretest loop
Counter loop
Posttest loop
Infinite loop
What happens if the condition of a while loop is false at the start?
The loop will cause an error
The loop will iterate indefinitely
The loop will iterate at least once
The loop will not iterate at all
What is an infinite loop?
A loop that executes a fixed number of times
A loop that never starts
A loop that repeats until interrupted
A loop that executes only once
What do the ++ and -- operators do?
Multiply and divide a variable
Reset a variable to zero
Add and subtract a variable
Increment and decrement a variable
What is the general format of a for loop?
for (Initialization; Test; Update) { statements }
while (BooleanExpression) { statements }
do { statements } while (BooleanExpression)
if (BooleanExpression) { statements }
What is the purpose of the StreamWriter class?
To read data from a text file
To write data to a text file
To delete a file
To create a new file
What does the OpenFileDialog control do?
Deletes a file
Creates a new file
Displays a dialog box for opening files
Displays a dialog box for saving files
Aiden is working on a project in .NET and needs to generate random numbers for his simulation. What is the purpose of the Random class in .NET?
To sort numbers
To display numbers
To generate random numbers
To store numbers in a file
During a computer science class, Priya is curious about the NextDouble method of the Random class. What does this method return?
An integer between 0 and 100
A floating-point number between 0.0 and 1.0
A random string
A boolean value
What is the Load event in an application that Olivia is developing?
An event that occurs when a file is saved
An event that occurs when the application is closed
An event that occurs when the form is loaded into memory
An event that occurs when a button is clicked
Sophia is learning about file handling in her programming class. What is the purpose of the Close method in file handling?
To read data from a file
To write data to a file
To open a file
To disconnect the file and the program
What is the difference between a for loop and a while loop?
A for loop is used for iterating over arrays, while a while loop is not
A for loop has a defined number of iterations, while a while loop continues until a condition is false
A for loop can only be used with integers, while a while loop can be used with any data type
There is no difference; they are interchangeable
What does the StreamReader class do in file handling?
To write data to a file
To read data from a file
To delete a file
To create a new file
