Difference between while and do while loop in C# | Code By Topic

Difference between while and do while loop in C#

In C# to perform the repetitive task you are free to use For, Foreach, While,or DoWhile loop. This loop is also called as C# Iteration Constructs.In This topic we will discuss about the difference between while and do while loop. While loop and do while is almost same behaviour and difference i mentioned below. Syntax is little bit different for while and do while loop.

Difference between while & do while in C#

While Do While
//Do Code Here
// Do Code Here

Nature & Execution Time
Takes less time to execute and the code is shorter. Takes more time to execute and code becomes longer. 
No semicolon(;) is used in last You have to use semicolon(;) in last as mentioned in syntax.
What First
Condition is checked first. Condition is checked later.
Important Point
Since condition is checked first, statements may or may not get executed. Since condition is checked later, the body statements will execute at least once.


Post a Comment