Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在结束前停止方法_Java_Android_Loops_Methods - Fatal编程技术网

Java 如何在结束前停止方法

Java 如何在结束前停止方法,java,android,loops,methods,Java,Android,Loops,Methods,我想知道如何停止读取方法中的代码,因为我有一个具有多个if()的方法,如果第一个方法已完成,那么第二个方法也将变得可读,等等: public void putPlayerInLadderBord() { if(player1Score < 0) { player1Score = currentPlayerScore; player1Name = currentPlayerName; player1.setText(player1

我想知道如何停止读取方法中的代码,因为我有一个具有多个if()的方法,如果第一个方法已完成,那么第二个方法也将变得可读,等等:

 public void putPlayerInLadderBord() {


    if(player1Score < 0) {
        player1Score = currentPlayerScore;
        player1Name = currentPlayerName;
        player1.setText(player1Name + " - Score : " + player1Score);
    }
    if (player1Score >= 0 && player2Score < 0) {
        player2Score = currentPlayerScore;
        player2Name = currentPlayerName;
        player2.setText(player2Name + " - Score : " + player2Score);
    }
    if (player1Score >= 0 && player2Score >= 0 && player3Score < 0) {
        player3Score = currentPlayerScore;
        player3Name = currentPlayerName;
        player3.setText(player3Name + " - Score : " + player3Score);
    }
    if (player1Score >= 0 && player2Score >= 0 && player3Score >= 0 && player4Score < 0) {
        player4Score = currentPlayerScore;
        player4Name = currentPlayerName;
        player4.setText(player4Name + " - Score : " + player4Score);
    }
    if (player1Score >= 0 && player2Score >= 0 && player3Score >= 0 && player4Score >= 0 && player5Score < 0) {
        player5Score = currentPlayerScore;
        player5Name = currentPlayerName;
        player5.setText(player5Name + " - Score : " + player5Score);
    }
}
public void puterlineladderbord(){
如果(player1Score<0){
player1Score=当前playerScore;
player1Name=currentPlayerName;
player1.setText(player1Name+“-分数:+player1Score);
}
如果(player1Score>=0&&player2Score<0){
player2Score=当前playerScore;
player2Name=当前playerName;
player2.setText(player2Name+“-分数:”+player2Score);
}
如果(player1Score>=0&&player2Score>=0&&player3Score<0){
player3Score=当前playerScore;
player3Name=当前playerName;
player3.setText(player3Name+“-分数:”+player3Score);
}
如果(player1Score>=0&&player2Score>=0&&player3Score>=0&&player4Score<0){
player4Score=当前playerScore;
player4Name=currentPlayerName;
player4.setText(player4Name+“-Score:+player4Score);
}
如果(player1Score>=0&&player2Score>=0&&player3Score>=0&&player4Score>=0&&player5Score<0){
player5Score=当前playerScore;
player5Name=currentPlayerName;
player5.setText(player5Name+“-Score:+player5Score);
}
}
结果,当一名玩家完成游戏时,他的分数+名字会出现在每一个LadderBord案例中^^ 我想在每个if之后添加类似stop()的内容,但我不知道是否可能/我可以使用什么语法!
谢谢

您的问题中没有循环,但您是在询问控制流。我想你想要这个。或者你可以用。一般来说,你是学习这类东西的一个很好的资源。

只需使用
return
.Hi,请使用return退出if条件,如下语句:return;对于上面的示例,您应该使用else if语句,而不是连续的if语句。