Decision Making and Looping Questions

By
1.) What are the Decision making statements in C#?
  • If statement
  • Switch statement
  • Conditional operator statement
2. ) What is the Syntax of Switch statement?
switch(expression)
{
case 1:
...........statements.........
break;

case 2:
...........statements.........
break;
default:
...........statements.........
break;

}
3. ) What is the Syntax of conditional operator?
conditional expression ? expression 1 : expression 2
4. ) What are the Looping statements in C#?
  •  While statement
  • do statement
  • for statement
  • foreach
5. ) What are the ways to create an infinite loop?
There are some ways to create an  infinite loop.
  • While 
  • do 
  • for
Ex.
while(1)
{
console.writeLine("Hello");
console.ReadLine();
}
   
6. ) What is the Break statement in C# ?
Break statement  is the cause to terminates the loop.
More Details...

7. ) What is the Continue statement in C# ?
 Continue is the cause to continue the loop with the next iteration after skipping any statement in between.The continue statement enable us to restart the current loop.
More Details...

8. ) What is the goto statement in C# ?
This statement uses the concept of level.A label is an valid c# variable name ending with a colon.
More Details...

9. ) What is Difference between for and foreach statement in C# ?
The foreach statement is similar to the for statement but implemented differently
  • In execution of for loop required three step (initialization,text-condition,increment)but in foreach statement required two step(type ,variable)
  • foreach statement automatically detects the boundaries of the collection being iterated over but for loop does not detect automatically. 
More Details...
10. ) Can i use switch statement instead of if-else statement?
Yes.

0 comments:

Post a comment

Powered by Blogger.