Search code examples
c#.netinfinite-loop

infinite loop example with minimum code in c#


Can you give me an infinite loop example on c# with minimum code? I came up with something but I thought there could be more easier way.


Solution

  • The typical examples are the for and while loops. For example

    for(;;)
    {}
    

    and

    while(true)
    {}
    

    However, basically any looping construct without a break or a terminating condition will loop infinitely. Different developers have different opinions on which style is best. Additionally, context may sway which method you choose.