wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Control Structures C#

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the purpose of control structures in programming?

a)

To perform calculations

b)

To manage the flow of execution in a program

c)

To store data

d)

To define objects

2.

Which of the following is NOT a type of control structure?

a)

Sequence

b)

Selection

c)

Iteration (Repetition)

d)

Encapsulation

3.

What does the `if` statement do in a program?

a)

It repeats a block of code

b)

It checks a condition and executes code if the condition is true

c)

It declares a variable

d)

It stops the execution of the program

4.

Which of the following is an example of a double-selection structure in C#?

a)

while loop

b)

if statement

c)

if...else statement

d)

do...while loop

5.

What does the conditional operator `?:` do in C#?

a)

It repeats a statement multiple times

b)

It acts as a ternary operator that replaces simple if...else statements

c)

It terminates a loop

d)

It breaks the execution of a switch statement

6.

What is a "counter-controlled repetition" structure?

a)

A loop where the number of iterations is known in advance

b)

A loop that runs indefinitely

c)

A loop that runs based on user input

d)

A structure used for function calls

7.

Which of the following loops guarantees at least one execution of the loop body?

a)

while loop

b)

for loop

c)

do...while loop

d)

switch statement

8.

What is the difference between a `while` loop and a `for` loop?

a)

A `while` loop is for selection, and a `for` loop is for repetition

b)

A `for` loop is more suitable for definite loops, while a `while` loop is used for indefinite loops

c)

A `for` loop executes only once, while a `while` loop repeats multiple times

d)

A `while` loop has an increment/decrement operator, while a `for` loop does not

9.

Which of the following is an example of sentinel-controlled repetition?

a)

A loop that runs exactly 10 times

b)

A loop that continues until the user inputs -1

c)

A loop that increments by 1

d)

A loop controlled by a counter variable

10.

What does the `break` statement do in a loop?

a)

It skips the current iteration and continues with the next

b)

It terminates the loop entirely

c)

It adds an extra iteration to the loop

d)

It restarts the loop

11.

What does the `continue` statement do in a loop?

a)

It stops the loop

b)

It terminates the program

c)

It skips the remaining statements in the current iteration and moves to the next iteration

d)

It reverses the loop direction

12.

Which of the following is an example of a compound assignment operator in C#?

a)

==

b)

+=

c)

<=

d)

!=

13.

What does the prefix increment operator `++var` do in C#?

a)

It increments the value of the variable after it is used

b)

It decrements the value of the variable before it is used

c)

It increments the value of the variable before it is used

d)

It multiplies the variable by 2

14.

What happens when the condition of a `while` loop evaluates to `false`?

a)

The loop continues to execute

b)

The loop body is executed once more

c)

The loop terminates and exits

d)

The loop skips the next iteration

15.

In a `switch` statement, what is the purpose of the `default` case?

a)

To terminate the switch statement

b)

To handle any case not explicitly matched by a `case` label

c)

To reset the switch statement

d)

To skip the rest of the cases

16.

Which of the following loops is counter-controlled?

a)

do...while loop

b)

for loop

c)

if statement

d)

switch statement

17.

Which of the following is a valid `for` loop structure in C#?

a)

`for (int i = 0; i < 10; i++) { /* statements */ }`

b)

`for (int i = 0; i++; i < 10) { /* statements */ }`

c)

`for (i < 10; int i = 0; i++) { /* statements */ }`

d)

`for (int i = 0; i < 10; i--) { /* statements */ }`

18.

Which loop structure is typically used when the number of iterations is known in advance?

a)

while loop

b)

do...while loop

c)

for loop

d)

switch statement

19.

What does the following code do: `for (int i = 0; i < 5; i++) { Console.WriteLine(i); }`?

a)

It prints numbers from 1 to 5

b)

It prints numbers from 0 to 4

c)

It prints numbers from 0 to 5

d)

It prints numbers from 1 to 4

20.

In a `do...while` loop, when is the condition checked?

a)

Before the loop starts

b)

After the loop body executes at least once

c)

After every iteration except the first

d)

The condition is not checked