
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to use C# do while loop?
The do...while loop checks its condition at the end of the loop. It is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
To create a do while loop −
do { statement(s); } while( condition );
The conditional expression appears at the end of the loop, so the statement(s) in the loop execute once before the condition is tested.
If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop execute again. This process repeats until the given condition becomes false.
The following is an example −
Example
using System; namespace Loops { class Program { static void Main(string[] args) { /* local variable definition */ int a = 50; /* do loop execution */ do { Console.WriteLine("value of a: {0}", a); a = a + 1; } while (a < 20); Console.ReadLine(); } } }
Output
value of a: 50
- Related Articles
- How to use ‘do while loop’ in Java?
- do…while loop vs. while loop in C/C++
- How do we use continue statement in a while loop in C#?
- How do we use a break statement in while loop in C#?
- How to use ‘while loop’ in Java?
- How to use nested while loop in JavaScript?
- How to emulate a do-while loop in Python?
- Difference Between while and do-while Loop
- Java do-while loop example
- Java infinite do-while loop
- Do-while loop in Arduino
- How to use PowerShell Break statement with the While Loop?
- The do…while loop in Javascript
- What are the differences between while loop and do-while loop in Java?
- How to create nested while loop in C#?

Advertisements