有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (3) 个答案

  1. # 1 楼答案

    不能将continue用作变量名,因为它是保留字

    the docs

    The continue statement skips the current iteration of a for, while, or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop.

    可以看出这是一个关键字,因为当您查看问题时,continue应用了语法突出显示,如booleanfalse

    boolean continue = false;
    

    那就像写作一样

    boolean boolean = false;
    

    boolean false = false;
    

    这两种方法显然都不起作用,因此请尝试其他类似continuing的方法:

    boolean continuing = false;
    
  2. # 2 楼答案

    请尝试以下方法:

    boolean cont = false;
    

    或者用另一个名字。关键是,在Java中,continue是一个keyword,不能用作变量名-在语言规范中它是正确的here。对于未来的reference,这就是continue的用途:

    The continue statement skips the current iteration of a for, while, or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop.

  3. # 3 楼答案

    不能将continue用作变量的名称。这是java保留字之一