当前位置:首页 > 开发 > 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

相关文章

获取鼠标坐标位置

方式1 //获取鼠标光标的位置(以屏幕坐标表示)    &...

C# 冒泡排序

int[] iage = { 11, 55,&nb...

C# Windows环境下以管理员启动

右键点击项目名称    -   ...

C# 可空参数

using System; using System.Runtime.Inte...

C# [OnPaint]和[OnPaintBackground]的区别

OnPaint和OnPaintBackground的主要功能区别OnPaint:OnPaint方法主...

C# BackgroundWorker,在DoWork里更新控件内容

一般情况下不可以直接在BackgroundWorker的DoWork事件中更新 UI 控件在Back...