当前位置:首页 > 开发 > C# > 正文内容

C# for,while,do while,switch

C#3年前 (2022-10-23)
for    
#region for

for (int i = 0; i < 30; i++)
{
    if (i == 10)
    {
        continue;//跳出本次循环
    }
    else if (i == 20)
    {
        break;//结束循环
    }
    Console.WriteLine(i);
}

#endregion


while    
#region for

for (int i = 0; i < 30; i++)
{
    if (i == 10)
    {
        continue;//跳出本次循环
    }
    else if (i == 20)
    {
        break;//结束循环
    }
    Console.WriteLine(i);
}

#endregion


do while    
#region do while

int i2 = 0;
do
{
    Console.WriteLine(i2);
    i2++;
} while (i2!=5);

#endregion


switch    
#region switch

int index = 2;
switch (index)
{
    case 0:
        Console.WriteLine("0");
        break;
    case 1:
        Console.WriteLine("1");
        break;
    case 2:
        Console.WriteLine("2");
        break;  
    default:
        Console.WriteLine("error");
        break;
}

#endregion



转载请注明出处。

本文链接:http://www.pythonopen.com/?id=222

相关文章

C# 延时命令

方法1System.Threading.Thread.Sleep(1000);缺点:如果在主线程使用...

C# 标准日期和时间格式说明符

Code说明Write备注Y年月2022年7月y标准日期和时间格式说明符2022年7月单独使用时y年...

C# 缩减代码量的一些方式

static void Main() { Thread thre...

C# BackgroundWorker

1.概述BackgroundWorker是一个在 WinForms 应用程序中用于简化在后台线程执行...

C# BackgroundWorker的例子

以下是一个使用 BackgroundWorker 组件在 C# 中实现后台执行任务,同时在主线程更新...

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...