Senior .Net Developer Question: Download Senior .Net Developer PDF

Tell us the difference between the while and for loop. Provide a .NET syntax for both loops?

Tweet Share WhatsApp

Answer:

Both 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 ]

Download Senior .Net Developer PDF Read All 60 Senior .Net Developer Questions
Previous QuestionNext Question
Explain me why do we use MSMQ?Tell us what do the following acronyms in .NET stand for: IL, CIL, MSIL, CLI and JIT?