zoukankan      html  css  js  c++  java
  • break,continue,return 区别

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace breakcontinue_test
    {
        class Program
        {
            static void Main(string[] args)
            {
                for (int i = 10; i > 3; i--)  //判断变量是否大于3,如果满足条件,开始循环
                {
                    Console.WriteLine("当前变量的值等于{0}", i); //输出变量值
                    break;     //跳出整个for循环   return 的作用跟break一样。
                    Console.WriteLine("看看这句是否输出呢?");   //没有输出说明跳出了循环
                }
                for (int i = 20; i > 13; i--)  //判断变量是否大于13,如果满足条件,开始循环
                {
                    Console.WriteLine("当前变量的值等于{0}", i); //输出变量值
                    continue;  //跳出本次循环,继续执行下次可执行的循环。
                    Console.WriteLine("看看这句是否输出呢?");   //没有输出说明跳出了循环
                }
            }
        }
    }

    总结:break;     //跳出整个for循环   return 的作用跟break一样。 continue;  //跳出本次循环,继续执行下次可执行的循环。

  • 相关阅读:
    [Leetcode] Median of Two Sorted Arrays
    [Jobdu] 题目1463:招聘会
    [Leetcode] Merge Two Sorted Lists
    [Leetcode] Combinations
    [Leetcode] Populating Next Right Pointers in Each Node II
    [Leetcode] Insertion Sort List
    redis在Web中的使用
    设计模式:单例模式
    设计模式:基本法则
    设计模式:工厂模式
  • 原文地址:https://www.cnblogs.com/ljan/p/3192845.html
Copyright © 2011-2022 走看看