Tell us the difference between the while and for loop. Provide a .NET syntax for both loops?
Submitted by: MuhammadBoth loops are used when a unit of code needs to execute repeatedly. The difference is that the for loop is used when you know how many times you need to iterate through the code. On the other hand, the while loop is used when you need to repeat something until a given statement is true.
The syntax of the while loop in C# is:
while (condition [is true])
{
// statements
}
The syntax of the while loop in VB.NET is:
While condition [is True]
' statements
End While
The syntax of the for loop in C# is:
for (initializer; condition; iterator)
{
// statements
}
The syntax of the for loop in VB.NET is:
For counter [ As datatype ] = start To end [ Step step ]
' statements
Next [ counter ]
Submitted by: Muhammad
The syntax of the while loop in C# is:
while (condition [is true])
{
// statements
}
The syntax of the while loop in VB.NET is:
While condition [is True]
' statements
End While
The syntax of the for loop in C# is:
for (initializer; condition; iterator)
{
// statements
}
The syntax of the for loop in VB.NET is:
For counter [ As datatype ] = start To end [ Step step ]
' statements
Next [ counter ]
Submitted by: Muhammad
Read Online Senior .Net Developer Job Interview Questions And Answers
Top Senior .Net Developer Questions
☺ | Explain me how does LINQ work? |
☺ | Explain me what is encapsulation? |
☺ | Tell us what is Heap and what is Stack? |
☺ | Explain what is Mutex? |
☺ | Please explain when should you use .NET Web Forms over ASP.NET MVC? |
Top Dot Net Technologies Categories
☺ | MSF Interview Questions. |
☺ | .Net Architecture Interview Questions. |
☺ | ASP.Net MVC Interview Questions. |
☺ | Entity Framework Interview Questions. |
☺ | C# (Sharp) Programming Language Interview Questions. |