NEW
Font size
WorksheetsControl Structures C#
Total questions: 20
Worksheet time: 10mins
What is the purpose of control structures in programming?
To perform calculations
To manage the flow of execution in a program
To store data
To define objects
Which of the following is NOT a type of control structure?
Sequence
Selection
Iteration (Repetition)
Encapsulation
What does the `if` statement do in a program?
It repeats a block of code
It checks a condition and executes code if the condition is true
It declares a variable
It stops the execution of the program
Which of the following is an example of a double-selection structure in C#?
while loop
if statement
if...else statement
do...while loop
What does the conditional operator `?:` do in C#?
It repeats a statement multiple times
It acts as a ternary operator that replaces simple if...else statements
It terminates a loop
It breaks the execution of a switch statement
What is a "counter-controlled repetition" structure?
A loop where the number of iterations is known in advance
A loop that runs indefinitely
A loop that runs based on user input
A structure used for function calls
Which of the following loops guarantees at least one execution of the loop body?
while loop
for loop
do...while loop
switch statement
What is the difference between a `while` loop and a `for` loop?
A `while` loop is for selection, and a `for` loop is for repetition
A `for` loop is more suitable for definite loops, while a `while` loop is used for indefinite loops
A `for` loop executes only once, while a `while` loop repeats multiple times
A `while` loop has an increment/decrement operator, while a `for` loop does not
Which of the following is an example of sentinel-controlled repetition?
A loop that runs exactly 10 times
A loop that continues until the user inputs -1
A loop that increments by 1
A loop controlled by a counter variable
What does the `break` statement do in a loop?
It skips the current iteration and continues with the next
It terminates the loop entirely
It adds an extra iteration to the loop
It restarts the loop
What does the `continue` statement do in a loop?
It stops the loop
It terminates the program
It skips the remaining statements in the current iteration and moves to the next iteration
It reverses the loop direction
Which of the following is an example of a compound assignment operator in C#?
==
+=
<=
!=
What does the prefix increment operator `++var` do in C#?
It increments the value of the variable after it is used
It decrements the value of the variable before it is used
It increments the value of the variable before it is used
It multiplies the variable by 2
What happens when the condition of a `while` loop evaluates to `false`?
The loop continues to execute
The loop body is executed once more
The loop terminates and exits
The loop skips the next iteration
In a `switch` statement, what is the purpose of the `default` case?
To terminate the switch statement
To handle any case not explicitly matched by a `case` label
To reset the switch statement
To skip the rest of the cases
Which of the following loops is counter-controlled?
do...while loop
for loop
if statement
switch statement
Which of the following is a valid `for` loop structure in C#?
`for (int i = 0; i < 10; i++) { /* statements */ }`
`for (int i = 0; i++; i < 10) { /* statements */ }`
`for (i < 10; int i = 0; i++) { /* statements */ }`
`for (int i = 0; i < 10; i--) { /* statements */ }`
Which loop structure is typically used when the number of iterations is known in advance?
while loop
do...while loop
for loop
switch statement
What does the following code do: `for (int i = 0; i < 5; i++) { Console.WriteLine(i); }`?
It prints numbers from 1 to 5
It prints numbers from 0 to 4
It prints numbers from 0 to 5
It prints numbers from 1 to 4
In a `do...while` loop, when is the condition checked?
Before the loop starts
After the loop body executes at least once
After every iteration except the first
The condition is not checked
