技术PHP-在同一循环中中断并继续

技术PHP-在同一循环中中断并继续,php,loops,break,continue,Php,Loops,Break,Continue,是否可以在2个循环中使用“中断/继续”而不使用变量?无2例;或中断2 示例不起作用: while(1) { // some code while(2) { // some code if(expr) { break; // break while(2) continue; // continue while(1) but never used } // some code } // some code } 带变量的解决方案

是否可以在2个循环中使用“中断/继续”而不使用变量?无2例;或中断2

示例不起作用:

while(1) {
  // some code
  while(2) {
    // some code
    if(expr) {
      break; // break while(2)
      continue; // continue while(1) but never used
    }
    // some code
  }
  // some code
}
带变量的解决方案:

while(1) {
  // some code
  $continue = false;
  while(2) {
    // some code
    if(expr) {
      $continue = true;
      break;
    }
    // some code
  }
  if($continue) {
    continue;
  }
  // some code
}
在while2循环中有中断/继续的解决方案吗?另一个最好的方法

编辑。数据示例:

for($i=0; $i < 100; $i++) {
    $a = mt_rand(0, 1000);
    for($j=0; $j < 100; $j++) {
      if($j === $a) {
        break; // and continue the first loop
      }
    }
    echo "how to never display this string if second loop break?";
} 

你不需要这些变量,只需暂时停止继续2如果expr为真,它将中断while2并继续while1。

如果我理解正确,你不需要在while1中继续,因为一旦while2中断,循环将再次启动,然后重新启动while2,直到再次满足条件。循环直到你打破才结束;而我猜,为了防止它需要跳过里面的内容,请使用ifexpr continue;will Dot这段代码维护起来会很糟糕,对每个程序员来说都是一场噩梦。哈哈,我知道,我没有编写这段代码,但我很好奇,只是一个技术问题。我写了另一个代码。