2009-07-30 112 views
3

在我的“本地”编程语言(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循环。

回答

18
continue; // Goto the next iteration 
break; // Exit the loop 
+0

1简洁明了;正是我喜欢在答案中看到的。 – 2009-07-30 15:48:26

+0

这就是为什么我将它标记为答案。它没有比这更清楚。 – 2009-07-30 16:12:33

1

使用continue关键字

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

的这个输出是:

9 
10