C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# Continue 继续语句

C# continue 语句用于继续循环。它继续程序的当前流程并在指定条件下跳过剩余的代码。在内部循环的情况下,它只继续内部循环。

句法 (Syntax)

jump-statement;    
continue;

C# 继续语句示例

例子 (Example)

using System;  
public class ContinueExample  
    {  
      public static void Main(string[] args)  
      {  
         for(int i=1;i<=10;i++){    
            if(i==5){    
                continue;    
            }    
            Console.WriteLine(i);    
        }    
      }  
   }

输出:

1
2
3
4
6
7
8
9
10

带有内循环的 C# Continue 语句

只有在内循环中使用 continue 语句时,C# Continue 语句才会继续内循环。

例子 (Example)

using System;  
public class ContinueExample  
    {  
      public static void Main(string[] args)  
      {  
          for(int i=1;i<=3;i++){      
                    for(int j=1;j<=3;j++){      
                        if(i==2&&j==2){      
                            continue;      
                        }      
                        Console.WriteLine(i+" "+j);      
                    }      
            }      
      }  
   }

输出:

1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3


上一主题 C# Break 中断语句 下一主题 C# Goto 转到语句
  • 使用社交账号登录,本站支持
全部评论(0)