Welcome to the C# Looping with the for Statement Quiz! This quiz will test your knowledge of loops in C#, focusing on the for loop and foreach loop constructs. You’ll explore key concepts such as loop syntax, variable scope, break and continue statements, nested loops, and the advantages of using different types of loops. Each question is designed to help you better understand how loops control the flow of execution in C# programs.
1.
What happens when you use the break statement inside a nested loop?
2.
What is the effect of the continue statement when used in a foreach loop?
3.
Which statement is true about nested loops in C#?
4.
When should you use a for loop instead of a foreach loop?
5.
What is the output of the following code?
string[] colors = { 'red', 'green', 'blue' };
foreach (string color in colors) {
Console.WriteLine(color);
}
6.
Which of the following statements about the foreach loop is true?
7.
What is the correct syntax for a foreach loop in C#?
8.
What is a foreach loop used for in C#?
9.
What is the output of the following code?
for (int i = 1; i < 10; i++) {
if (i % 2 != 0)
continue;
Console.WriteLine(i);
}
10.
What is the purpose of the continue statement in a for loop?
11.
What is the primary purpose of loops in C#?
12.
How do nested for loops work?
13.
What is variable scope in relation to for loops?
14.
How do you create an infinite for loop in C#?
15.
What does the loop expression do in a for loop?
16.
What is the purpose of the break statement in a loop?
17.
What happens if the conditional expression in a for loop is false at the start?
18.
What does the initializer element in a for loop do?
19.
Which of the following is the correct syntax for a basic C# for loop?