Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Infinite Loop in C #

Shulou Source: shulou.com Published: 2022-06-01 02:06:31 09月17日 Update

This article mainly explains "how C#realizes infinite loop". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "C#how to realize infinite loop"!

loop control statement

Loop control statements change the normal sequence of execution. When execution leaves a scope, all automatic objects created in that scope are destroyed.

C#provides the following control statements. Click on the link to see details of each statement.

A control statement describes a break statement terminating a loop or switch statement, and program flow continues with the next statement immediately following the loop or switch. The continue statement causes the loop to skip the rest of the body and immediately restart the test condition. infinite loop

If the condition is never false, the loop becomes an infinite loop. The for loop is traditionally used to implement an infinite loop. Since none of the three expressions that make up the loop are required, you can leave certain conditional expressions blank to make an infinite loop.

examples

using System;

namespace Loops

{

class Program

{

static void Main(string[] args)

{

for (; ; )

{

Console.WriteLine("Hey! I am Trapped");

}

}

}

}

When the conditional expression does not exist, it is assumed to be true. You can also set an initial value and increment expression, but in general programmers prefer to use the for(;;) construct to represent an infinite loop.

At this point, I believe everyone has a deeper understanding of "how C#realizes infinite loop," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Loop statement conditional expression control content program scope learning practical deeper three subject traditional interest increment example practicality practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn Xiaomi MySQL Linux