嗨我一直试图在过去的一小时内打破这个循环并继续,因为已经满足了我的条件一次。我的应用程序几乎读取一系列的行并分析它,然后打印所述的变量。的线条的外观等的例子(在不包括在内):如何在满足条件后从循环中断开
- 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