The switch statement is a control statement that selects a switch section to execute from a list of candidates.
Back
Give an example of 'While loop' statement?
Front
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number = 0;
while(number < 5)
{
Console.WriteLine(number);
number = number + 1;
}
Console.ReadLine();
}
}
}
Back
Give an example of 'switch' control statement?
Front
int caseSwitch = 1;
switch (caseSwitch)
{
case 1:
Console.WriteLine("Case 1");
break;
case 2:
Console.WriteLine("Case 2");
break;
default:
Console.WriteLine("Default case");
break;
}
Back
Can 'switch' statement have one or more labels?
Front
Yes
Back
Give an example of 'if-else' control statement?
Front
if (condition) { //code here } else {//code here}
Back
Is 'else' mandatory in 'if-else' control statement?
Front
No it is not
Back
Which keywords are used in control statements?
Front
The keywords used in selection statements are if, else, switch, case, default
Back
Where can I find more information about switch Statements in C Sharp?
A switch statement includes one or more switch sections. Each switch section contains one or more case labels followed by one or more statements.
Back
What if i want nested 'if-else' control statements? Are they allowed?
Front
Yes. Example if (condition1) { if (condition2) { } }
Back
Give an example of 'For loop' statement?
Front
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number = 5;
for (int i = 0; i < number; i++)
Console.WriteLine(i);
Console.ReadLine();
}
}
}