Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# do while

作者:若离   发布日期:2025-07-25   浏览:41

// C# do-while 循环示例

using System;

class Program
{
    static void Main()
    {
        int count = 0;
        do
        {
            Console.WriteLine("Count: " + count);
            count++;
        } while (count < 5);
    }
}

解释说明:

  1. do-while 循环:与 while 循环不同,do-while 循环会先执行一次循环体中的代码,然后再检查条件。因此,即使条件一开始为 false,循环体也会至少执行一次。
  2. 变量 count:用于记录循环的次数,初始值为 0。
  3. 循环体:在每次循环中,打印当前的 count 值,并将 count 增加 1。
  4. 条件判断:当 count 小于 5 时,继续循环;否则,退出循环。

这个例子会输出以下内容:

Count: 0
Count: 1
Count: 2
Count: 3
Count: 4

上一篇:c# tcp

下一篇:cursor c#

大家都在看

c# 二进制

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#游戏开发

c#网络编程

c# rectangle

c# 取字符串最后一个字符

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站