
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements