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

C# for,while,do while,switch

C#4年前 (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://pythonopen.com/?id=222

相关文章

C# SHA1

GetFileSHA1        ...

C# 跳出foreach循环

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

C# double转为string并保留两位小数

在 C# 中,可以使用多种方式将 double 类型的数据转换为 string 类型并保留两位小数,...

C# Browsable(bool)

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

C# Control防闪烁

SetStyle(ControlStyles.AllPaintingInWmPaint |...

C# i++和++i的区别

核心区别操作顺序            ...