Q1.
What will be the output of the following code?
int x = 10; if (x > 5) Console.WriteLine("Greater"); else Console.WriteLine("Smaller");
1
1
Smaller
2
Greater
3
Error
4
None
Q2.
Which loop is guaranteed to execute at least once?
1
1
while
2
do while
3
for
4
foreach
Q3.
What will be the output of the following code?
for (int i = 0; i < 3; i++) { if (i == 1) continue; Console.Write(i); }
1
1
01
2
012
3
02
4
123
Q4.
Which statement exits the current loop entirely?
1
1
break
2
return
3
exit
4
continue
Q5.
What will be the output of the following code?
int i = 0; while (i < 3) { Console.Write(i); i++; }
1
1
02
2
012
3
0123
4
123
Q6.
Which keyword is used to jump to a labeled statement?
1
1
break
2
return
3
goto
4
label
Q7.
What will be the output of the following code?
int i = 0; do { Console.Write(i); i++; } while (i < 2);
1
1
0
2
01
3
1
4
012
Q8.
Which of the following is not a valid control statement?
1
1
switch
2
repeat
3
for
4
if
Q9.
Which control structure is best for menu-driven programs?
1
1
switch
2
while
3
for
4
if
Q10.
How many times will this loop run?
for (int i = 0; i < 5; i += 2) Console.Write(i);
1
1
2
2
4
3
3
4
5
Q11.
What happens when break is used in a switch?
1
1
Exits the entire program
2
Skips all remaining cases
3
Exits the current loop
4
Terminates current case block
Q12.
What is printed by this code?
int x = 3; switch (x) { case 1: Console.WriteLine("One"); break; case 2: Console.WriteLine("Two"); break; default: Console.WriteLine("Default"); break; }
1
1
One
2
Default
3
Error
4
Two
Q13.
Which loop should you use when you don’t know how many times to run?
1
1
for
2
while
3
foreach
4
do while
Q14.
Can a switch work with strings in C#?
1
1
yes
2
no
3
Only with enums
4
Only in .NET Core
Q15.
What will be the output of the following code?
int a = 5; if (a % 2 == 0) Console.Write("Even"); else Console.Write("Odd");
1
1
Even
2
Odd
3
Error
4
Nothing
Q16.
Which loop is ideal for iterating over arrays?
1
1
foreach
2
while
3
for
4
do while
Q17.
What will be the output of the following code?
int[] arr = { 1, 2, 3 }; foreach (int item in arr) Console.Write(item);
1
1
1 2 3
2
123
3
321
4
Error
Q18.
What is true about nested control structures?
1
1
Not allowed in C#
2
Only two levels allowed
3
Can be nested indefinitely
4
Must use switch
Q19.
What will be the output of the following code?
for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) Console.Write("*"); }
1
1
***
2
******
3
Error
4
****
Q20.
What will this continue do in a while loop?
int i = 0; while (i < 5) { i++; if (i == 3) continue; Console.Write(i); }
1
1
Skips printing 3
2
Infinite loop
3
Error
4
Skips incrementing