
- 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
What types of loops are supported in C#?
A loop statement allows us to execute a statement or a group of statements multiple times. The following are the loops supported in C# −
Sr.No | Loop Type & Description |
---|---|
1 | while loop It repeats a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body. |
2 | for loop It executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. |
3 | do...while loop It is similar to a while statement, except that it tests the condition at the end of the loop body |
With C#, you can also use foreach loop as shown below −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int [] n = new int[10]; /* n is an array of 10 integers */ /* initialize elements of array n */ for ( int i = 0; i < 10; i++ ) { n[i] = i + 100; } /* output each array element's value */ foreach (int j in n ) { int i = j-100; Console.WriteLine("Element[{0}] = {1}", i, j); } Console.ReadKey(); } } }
Output
Element[0] = 100 Element[1] = 101 Element[2] = 102 Element[3] = 103 Element[4] = 104 Element[5] = 105 Element[6] = 106 Element[7] = 107 Element[8] = 108 Element[9] = 109
- Related Articles
- What are the data types supported by JDBC?
- Types of graphics are supported by HTML5?
- What are the different types of conditional statements supported by C#?
- How many groups of data types are supported by MySQL?
- How many DATE data types are supported by MySQL?
- What are the MySQL Supported Platforms?
- Can we get the supported image types in Java
- What implicit objects are supported by JSP?
- What are the best practices for using loops in Python?
- What are common HTML Events supported by JavaScript?
- What are the methods supported by W3C DOM?
- What are the escape sequences supported by C#?
- What are the parameters supported by Get-ChildItem in PowerShell?
- What are the types of ICMP message types?
- What are the document methods supported by Legacy DOM?

Advertisements