@nakov/

infinite-loop-with-break-csharp

C#

Calculating the first 5 results that match a condition, using infinite loop with `break` in C#

fork
loading
Files
  • main.cs
  • main.exe

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.24859851119787435","path":"main.cs","file":{"path":"main.cs","content":{"asEncoding":{"base64":"dXNpbmcgU3lzdGVtOwoKY2xhc3MgSW5maW5pdGVMb29wV2l0aEJyZWFrRXhhbXBsZSB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpIHsKICAgICAgICBpbnQgdmFsdWUgPSAwLCBtaW4gPSAxMDAwMDAsIGNvdW50ID0gMDsKICAgICAgICB3aGlsZSAodHJ1ZSkKICAgICAgICB7CiAgICAgICAgICAgIHZhbHVlID0gMiAqIHZhbHVlICsgMTsKICAgICAgICAgICAgaWYgKHZhbHVlID4gbWluKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSh2YWx1ZSk7CiAgICAgICAgICAgICAgICBjb3VudCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb3VudCA9PSA1KQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfSAgICAgICAKICAgIH0KfQo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;

class InfiniteLoopWithBreakExample {
    public static void Main() {
        int value = 0, min = 100000, count = 0;
        while (true)
        {
            value = 2 * value + 1;
            if (value > min)
            {
                Console.WriteLine(value);
                count++;
            }
            if (count == 5)
                break;
        }       
    }
}