C# do While Loop

imagen1
In this chapter you will learn:

  • What is do while loop in C#?
  • How it different from while loop?
  • How to use do while loop in C#?

do while loop treats same as while loop but only differences between them is that, do while executes at least one time. The code executes first then check for specified loop condition. But in while loop, the specified loop condition evaluated first then executes the code. A simple demonstration will help you to figure out do while loop more clearly.


do while-loop flow chart

Example:

Note: You must put semi-colon(;) at the end of while condition in do…while loop.

Output

12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 92
12 x 9 = 108
12 x 10 = 120
__

Summary

In this chapter you learned what is do while loop and how to use it in C# programming. In next chapter you will learn about for loop in C#.


Leave a Reply

Your email address will not be published. Required fields are marked *