【发布时间】:2014-04-23 09:49:08
【问题描述】:
我有这样的代码
while(setIterator.hasNext()){
String key = setIterator.next();
if(key.equalsIgnoreCase("location_id")){
containlocationid = true;
int id_key = Integer.parseInt(requestMap.get(key));
if(player.isLocationExists(id_key) == true){
player.setlocationID(Integer.parseInt(requestMap.get(key)));
responseOut.println("NOW WILL NOT BREAK AND SAVE");
}else{
responseOut.println("NOW WILL BREAK AND NO SAVE");
break;
}
}else if(key.equalsIgnoreCase("name")){
player.setName(requestMap.get(key));
responseOut.println("this is inside NAME");
}else if(key.equalsIgnoreCase("description")){
player.setDescription(requestMap.get(key));
responseOut.println("this is inside DESCRIPTION");
}
}
当得到布尔值“false”时,while 循环将中断并打印“NOW WILL BREAK AND NO SAVE”。但是现在我得到了这样的结果
this is inside NAME <- this will not print out after break while loop
this is inside DESCRIPTION <- this will not print out after break while loop
NOW WILL BREAK AND NO SAVE
表示保存成功,break不生效。我试了"Outer:" & "break Outer;"功能,但也失败了。
希望你明白我在说什么,请帮忙,谢谢!
【问题讨论】:
-
请做适当的缩进
-
您的集合似乎按顺序包含“名称”、“描述”和“位置 ID”之类的内容。而 isLocationExists() 方法返回 false
-
是不是按照“name”、“description”、“location_id”的顺序获取密钥。在这种情况下,我猜打印的输出是正确的
-
从输出来看,break 似乎工作正常 - 您的迭代器返回
name、description和location_id然后player.isLocationExists(id_key)返回false并且循环中断 -
是的..我不知道。我花了一整天来解决这个问题。