在java中使用goto语句时表达式的启动非法

在java中使用goto语句时表达式的启动非法,java,goto,Java,Goto,我试图使用goto语句重新开始玩家的回合,但它 不工作 goto不是Java的一部分。也许你在想另一种语言 正如blurfus指出的,即使在允许转到的语言中,也不应该使用它。这不是一个好的编程,因为它鼓励缺乏结构和“意大利面代码” 改为使用循环: while (true) { System.out.println("Player "+player+"'s Turn:"); System.out.print("Row : "

我试图使用goto语句重新开始玩家的回合,但它 不工作


goto
不是Java的一部分。也许你在想另一种语言

正如blurfus指出的,即使在允许
转到
的语言中,也不应该使用它。这不是一个好的编程,因为它鼓励缺乏结构和“意大利面代码”

改为使用循环:

while (true) {
    System.out.println("Player "+player+"'s Turn:");
    System.out.print("Row : ");
    row=s.nextInt();
    System.out.print("Column : ");
    column=s.nextInt();

    if(indexValidate(arr,row,column)) {
        arr[row][column]=player;
        break;  // terminate while loop
    }
}

不要使用
goto
。。。糟糕的编程选择。相反,使用一个循环(如
,而(spaceCheck(arr)){…}
)在Java中没有goto语句。
while (true) {
    System.out.println("Player "+player+"'s Turn:");
    System.out.print("Row : ");
    row=s.nextInt();
    System.out.print("Column : ");
    column=s.nextInt();

    if(indexValidate(arr,row,column)) {
        arr[row][column]=player;
        break;  // terminate while loop
    }
}