Q1)What is Difference between For Loop and For-Each Loop in C#?
- For loop iterates a statement or a block of statements repeatedly until a specified expression evaluates to false.
- For-each loop is used to iterate through the items in object collections, List generic collections or array list collections.
- Performance: For Loops are faster than For-each Loop. If we iterate array list or any collection with for loop and for-each loop then you will find time consumed by a for-each loop is much more than for loop so For loops are faster than For-each loop.
Q2) What is mean by Conditional statement?
Ans: A block of code that gets executed basis on a condition is known as conditional Statement. These are of two types:
- Conditional Branching
- Conditional Looping.
Q3)What is mean by Conditional Branching?
Ans: These statements allow us to branch our code depending on whether certain condition was met or not. C# has two constructs for branching code
- If
- Switch
Q4)What is mean by Conditional Looping?
Ans: C# provides three different loops that allows us to execute a block of code repeatedly until a certain condition is met, those are
- For Loop
- While Loop
- Do While Loop
Every Loop requires three things in common.
- Initialization: That sets the starting point of the loop.
- Condition: That sets the ending point of the loop.
- Iteration: Which takes you to the next level of the cycle either forward or backward direction.
Q5)
No comments:
Post a Comment