Control Instructions Questions

Practice Control Instructions MCQs with answers and explanations. Page 1 of 3.

Category
C# Programming
Topic
Control Instructions
Page
1 / 3
Mode
Practice

Questions

Open any question to view the answer and explanation.

Which of the following can terminate a while loop and transfer control outside the loop? 1) exit 2) while 3) continue 4) break 5) goto
Open
View answer
Identify the correct statements about C# control statements: 1) A switch statement can act on numerical as well as Boolean types. 2) A switch statement can act on characters, strings, and enumeration types. 3) We cannot declare variables within a case unless the statements are enclosed by { }. 4) foreach should be used to change a collection to avoid unpredictable side effects. 5) All expressions of the for statement are not optional.
Open
View answer
What will be the output of the following C#.NET code? int val; for (val = -5; val <= 5; val++) { switch (val) { case 0: Console.Write("India"); break; } if (val > 0) Console.Write("B"); else if (val < 0) Console.Write("X"); }
Open
View answer
Which of the following statements is correct regarding C# selection statements?
Open
View answer
C#.NET — Trace the loop and short-circuiting branches to determine printed output. int i; for (i = 0; i <= 10; i++) { if (i == 4) { Console.Write(i + " "); continue; } else if (i != 4) Console.Write(i + " "); else break; }
Open
View answer
C#.NET — Evaluate truth, short-circuiting, and condition outcomes for: if (age > 18 && no < 11) a = 25;
Open
View answer
C#.NET — Determine the printed output by evaluating bitwise precedence and Convert.ToBoolean. int i = 2, j = i; if (Convert.ToBoolean((i | (j & 5)) & (j - 25 * 1))) Console.WriteLine(1); else Console.WriteLine(0);
Open
View answer
C#.NET — Evaluate bitwise OR of character literals and switch grouping result. char ch = Convert.ToChar('a' | 'b' | 'c'); switch (ch) { case 'A': case 'a': Console.WriteLine("case A | case a"); break; case 'B': case 'b': Console.WriteLine("case B | case b"); break; case 'C': case 'c': case 'D': case 'd': Console.WriteLine("case D | case d"); break; }
Open
View answer
C#.NET — Validity of case labels in switch with variables. int i, j, id = 0; switch (id) { case i: Console.WriteLine("I am in Case i"); break; case j: Console.WriteLine("I am in Case j"); break; }
Open
View answer
C#.NET — Identify invalid switch-case labels and default usage. switch (id) { case 6: grp = "Grp B"; break; case 13: grp = "Grp D"; break; case 1: grp = "Grp A"; break; case ls > 20: grp = "Grp E"; break; case Else: grp = "Grp F"; break; }
Open
View answer
C#.NET — Determine switch output when switching on an enum value. namespace CuriousTabConsoleApplication { public enum color { red, green, blue }; class SampleProgram { static void Main(string[] args) { color c = color.blue; switch (c) { case color.red: Console.WriteLine(color.red); break; case color.green: Console.WriteLine(color.green); break; case color.blue: Console.WriteLine(color.blue); break; } } } }
Open
View answer
C#.NET — Use the conditional (ternary) operator to rewrite: int a = 1, b = 2, c = 0; if (a < b) c = a;
Open
View answer
C#.NET — Rewrite do-while as an equivalent looping construct. int i = 0; do { Console.WriteLine(i); i += 1; } while (i <= 10);
Open
View answer
C#.NET — Identify the incorrect decision-control form among common if/else patterns.
Open
View answer
C#.NET — Trace an infinite-for loop with conditional decrement and break to predict printed sequence. int i = 20; for (;;) { Console.Write(i + " "); if (i >= -10) i -= 4; else break; }
Open
View answer
C#.NET — Choose the valid loop that prints all characters of: char[] arr = new char[] { 'k', 'i', 'C', 'i', 't' };
Open
View answer
C#.NET — Which snippets correctly classify an integer as Odd or Even (consider operators and definite assignment)?
Open
View answer
C#.NET — Follow goto-based loop to find printed range. int i = 0, j = 0; label: i++; j += i; if (i < 10) { Console.Write(i + " "); goto label; }
Open
View answer
C#.NET — Understand logical OR (||), short-circuit evaluation, and when an assignment executes. Given: if (age > 18 || no < 11) a = 25; Which statements are correct?
Open
View answer
C#.NET — Identify the numeric series printed by the loop (recognize Fibonacci update pattern). int i = 1, j = 1, val; while (i < 25) { Console.Write(j + " "); val = i + j; j = i; i = val; }
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.