C# Do-While Loops :

do-while loop :

The do-while loop is similar to the while loop, but it checks the condition after each execution of its loop body. This type of loops is called loops with condition at the end (post-test loop).

The do-while loop is used when we want to guarantee that the sequence of operations in it will be executed repeatedly and at least once in the beginning of the loop. A do-while loop looks like this:

Syntax :

executable code;
while (condition);

Example :

  1. /* Description: calculate the factorial of a given number N */
  2. using System;
  3. namespace DemoProgramming
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. Console.Write("n = ");
  10. int n = int.Parse(Console.ReadLine());
  11. decimal factorial = 1;
  12. do
  13. {
  14. factorial *= n;
  15. n--;
  16. } while (n > 0);
  17. Console.WriteLine("n! = " + factorial);
  18. Console.ReadKey();
  19. }
  20. }
  21. }

Output :

C Sharp Language calculate the factorial of a given number N

Next Update


Currently we improved our website User Interface and other contents. Our next update is adding video tutorials on this site so, We create a new YouTube channel, our YouTube channel name is CodeX.

We need some time for make video tutorials (CodeX) so, stay with us and keep supporting and you know already we make a Collaboration with HackIsOn YouTube channel long time ago So, please Subscribe Our Channels