Do .. While loop in C#?

后端 未结 8 1191
后悔当初
后悔当初 2020-12-18 18:21

How do I write a Do .. While loop in C#?

(Edit: I am a VB.NET programmer trying to make the move to C#, so I do have experience with .NET / VB syntax. Thanks!)

8条回答
  •  佛祖请我去吃肉
    2020-12-18 18:56

    using System;
    
    class MainClass
    {
        public static void Main()
        {
            int i = 0;
            do
            {
                Console.WriteLine("Number is {0}", i);
                i++;
            } while (i < 100);
        }
    }
    

    Another method would be

    using System;
    
    class MainClass
    {
        public static void Main()
        {
            int i = 0;
            while(i <100)
            {
                Console.WriteLine("Number is {0}", i);
                i++;
            }
        }
    }
    

提交回复
热议问题