if文内にif文があります。私は私のbreak文を入れJavaでのループの停止
while(running)
{
System.out.println("Your current balance is: " + balance);
System.out.println("How much would you like to gamble this round?");
gamble = scan.nextInt();
if(gamble > balance)
{
System.out.println("Error : Cannot gamble more than your balance");
System.out.println("Enter a new bet less than " + balance);
gamble = scan.nextInt();
}
System.out.println("Dealing cards...");
if(deck >= 3)
{
card1 = rand.nextInt(12) + 2;
card2 = rand.nextInt(12) + 2;
card3 = rand.nextInt(12) + 2;
deck = deck - 3;
}
else
{
System.out.println("Not enough cards left in the deck");
System.out.println("Ending simulation...");
}
System.out.println("Your first card value is : " + card1);
System.out.println("Your second card value is : " + card2);
if(card1 == card2)
{
System.out.println("Same value for both cards! You win 2 chips!");
balance = balance + 2;
System.out.println("Play again? Type 'Y' for yes or 'N' for no");
playAgain = scan.next();
if(playAgain == "Y")
{
break;
}
else
{
running = false;
}
}
最初のコードをお見せしましょう、私はそれがwhileループの先頭に戻る必要があるが、それが唯一のif文1を抜け出しています。私のコードをwhileループの最上位に送るステートメントについて、どうやって行くことができますか?
coninueは私がしたい – stinepike
を継続し続けますこれが重複するとマークされている質問は全く同じ質問ではないことに注意してください。これはブレーク対オンスの誤解であり、コードにネストされたループはありません –