当前位置:首页 > 开发 > 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# 数据类型

Type ByteLenghtMinMax.NET Framework Typedefau...

C# 判断鼠标按键

private void button1_MouseDown(object&nb...

C# 跳出foreach循环

在 C# 中,如果你想在 foreach 循环内部提前跳出当前这一轮循环,继续执行下一轮循环,可以使...

C# BackgroundWorker的例子

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

C# decimal

概述在 C# 中,decimal是一种数据类型,用于表示高精度的十进制数值。它主要用于需要精确计算的...

C# 类接口

定义接口是一种抽象类型,它定义了一组方法签名(方法名称、参数列表和返回类型),但没有方法体。接口用于...