加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

.net – 在哪里做…循环没有条件记录?

发布时间:2020-12-17 07:21:46 所属栏目:百科 来源:网络整理
导读:显然,可以创建一个没有条件的Do … Loop-Loop.以下代码使用.NET 4.5( fiddle)以及Roslyn( fiddle)编译: Public Sub Main() Do Console.WriteLine("Hello World") Exit Do LoopEnd Sub 但是,documentation page上的语法仅提供以下两个选项: Do { While | Un
显然,可以创建一个没有条件的Do … Loop-Loop.以下代码使用.NET 4.5( fiddle)以及Roslyn( fiddle)编译:

Public Sub Main()
    Do
        Console.WriteLine("Hello World")
        Exit Do
    Loop
End Sub

但是,documentation page上的语法仅提供以下两个选项:

Do { While | Until } condition
    [ statements ]
    [ Continue Do ]
    [ statements ]
    [ Exit Do ]
    [ statements ]
Loop
-or-
Do
    [ statements ]
    [ Continue Do ]
    [ statements ]
    [ Exit Do ]
    [ statements ]
Loop { While | Until } condition

这是编译器中的错误,文档中的错误还是我看起来不够努力?

解决方法

如有疑问,请咨询 language specification,而不是参考:

10.9.1 While…End While and Do…Loop Statements

A While or Do loop statement loops based on a Boolean expression. … An expression
may be placed after the Do keyword or after the Loop keyword,but not
after both. … It
is also valid to specify no expression at all;

(我的重点)

语言参考试图更简单,但可能会丢失必要的细节.语言规范应该与编译器实现的匹配.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读