嗨我一直試圖在過去的一小時內打破這個循環並繼續,因爲已經滿足了我的條件一次。我的應用程序幾乎讀取一系列的行並分析它,然後打印所述的變量。的線條的外觀等的例子(在不包括在內):如何在滿足條件後從循環中斷開
- 10 C = 9 + 3
- 20 = C + 1
- 30打印Ç
- 40轉到20
- 50月底
它做的一切權利,當它到達40行轉到行20如預期,但我想它去線50,因爲已經就去排隊40次。這裏是我的這部分代碼:
while(booleanValue)
{
if(aString.substring(0, 4).equals("goto"))
{
int chosenLine = Integer.parseInt(b.substring(5));
if(inTheVector.contains(chosenLine))
{
analizeCommands(inTheVector.indexOf(chosenLine));
i++;
}
else
{
System.ou.println("Line Was Not Found");
i++;
}
}
else if(aString.substring(0, 3).equals("end"))
{
System.out.println("Application Ended");
booleanValue = false;
}
}
小改進:你可以用'aString.startsWith(「goto」)'替換'aString.substring(0,4).equals(「goto」)'。它對於短於4個字符的字符串更具可讀性和安全性。 – Pshemo 2013-04-29 00:30:21
您需要一個命令來說'if statement'並對其進行評估。 –
2013-04-29 00:30:29
也許'繼續'關鍵字會工作? – Pol0nium 2013-04-29 00:30:29