在我的“原生”中编程语言(RPG),我可以写一个循环,然后离开循环或强制迭代。它有点像GOTO。

dow (x < 999);
  read file;
  if (%eof);
    leave; // Leave the loop
  endif;
  if (field <> fileField);
    iter; // Iterate to the next record
  endif;
enddo;

我的问题是,是否有类似的选项是C#。就我而言,我正在使用foreach循环。

有帮助吗?

解决方案

continue; // Goto the next iteration
break; // Exit the loop

其他提示

中断将退出循环。 继续将跳转到下一次迭代。

使用继续关键字

for (int i = 1; i <= 10; i++) 
  {
     if (i < 9) 
        continue;
     Console.WriteLine(i);
  }

输出是:

9
10
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top