嗨,我过去的一个小时一直在尝试从这个循环中跳出并继续,因为已经满足了我的条件。我的应用程序基本上读取一系列的行,并分析它,然后打印所声明的变量。以下是这些行的示例(不包括 . ):
- 10 c = 9+3
- 20 a = c+1
- 30 print c
- 40 goto 20
- 50 end
当它到达第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.substring(0, 4).equals("goto")
替换为aString.startsWith("goto")
。这样更易读,对于长度小于4个字符的字符串也更安全。 - Pshemoif <condition> statement
并且对其进行评估。 - Luiggi Mendozaif-else-if-else
代码块的排序有些奇怪。else if
应该放在else
之前。 - Makoto