以下是我所知的大致可行的两种方式:
for (){
for (){
if (found the target) goto cont;
}
}
cont:;
我看到很多人强烈反对使用 goto
,但我认为这是一个相当合适的使用方式。
bool exit=false;
for (){
for (){
if (found the target){
exit=true;
break;
}
}
if (exit) break;
}
我以这种方式写了更多的代码。
你认为应该如何正确地完成这个任务?
return
语句,而非goto
或break
。 - Eljaygoto
被认为是合适的。请参阅这个最受欢迎的答案获取更多信息。 - Andreas Wenzel