
- 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 create an infinite loop in C#?
An infinite loop is a loop that never terminates and repeats indefinitely.
Let us see an example to create an infinite loop in C#.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { for (int a = 0; a < 50; a--) { Console.WriteLine("value : {0}", a); } Console.ReadLine(); } } }
Above, the loop executes until a < 50. The value of is set to 0 initially.
int a = 0;
The value of a decrements after each iteration since it is set to.
a--;
Therefore the value of a will never be above 50 and the condition a <50 will be true always. This will make the loop an infinite loop.
- Related Articles
- How to run an infinite loop in Tkinter?
- How to stop an infinite loop safely in Python?
- How do you create a Tkinter GUI stop button to break an infinite loop?
- How we can come out of an infinite loop in Python?
- Infinite while loop in Java
- The Infinite Loop in Perl
- Java infinite for loop
- Incremental Java infinite loop
- What keyboard command we have to stop an infinite loop in Python?
- How to create nested while loop in C#?
- Java infinite do-while loop
- How to create the loop structure in LESS
- How to loop through all values of an enum in C#?
- How to create an OrderedDictionary in C#?
- Find minimum moves to reach target on an infinite line in C++

Advertisements