zoukankan      html  css  js  c++  java
  • break、continue、return

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace _12_return
    {
        class Program
        {
            public static void Main(string[] args)
            {
    
    
                //1)break  直接跳出当前的循环,从当前循环外面开始执行,忽略循环体中任何其他语句和循环条件测试。
                //它只能跳出一层循环,如果你的循环是嵌套循环,那么你需要按照你嵌套的层次,逐步使用break来跳出.
    
                //for (int i = 0; i < 10; i++)
                //{
                //    for (int j = 0; j < 10; j++)
                //    {
                //        Console.WriteLine(j);
                //        break;
                //    }
                //    //break;
                //}
    
    
                //2)continue  终止当前的循环过程,但他并不跳出循环,而是继续往下判断循环条件执行语句.它只能结束循环中的一次过程,但不能终止循环继续进行.
                //只能用在while语句、do/ while语句、for语句、或者for / in语句的循环体内,在其它地方使用都会引起错误! 
                //for (int j = 0; j < 10; j++)
                //{
                //    Console.WriteLine(j);
                //    continue;
                //    Console.WriteLine("Hello World");//continue下面的语句不在执行,直接进入下一次循环的判断语句。
                //}
    
    
    
                //3)return作用
                //1、在方法中返回要返回的值。
                //2、立即结束本次方法。
    
                //例一
    
                //for (int j = 0; j < 10; j++)
                //{
                //    Console.WriteLine(j);
                //    return;//跳出循环
                //    Console.WriteLine("Hello World");
                //}
                //注意:return一般用于方法,而不是循环。上面只是演示用于循环的效果。
    
           //例二
                Console.WriteLine(Test(7));
            Console.WriteLine("程序已经跳出循环"); Console.ReadKey(); } public static int Test(int i) { int a=i+8; return a;//返回值,结束方法,后面代码不在执行。 Console.WriteLine("我还会被执行吗?"); } } }
  • 相关阅读:
    CodeForces 797D Broken BST
    CodeForces 797C Minimal string
    CodeForces 797B Odd sum
    CodeForces 797A k-Factorization
    CodeForces 772B Volatile Kite
    OpenCV学习笔记二十:opencv_ts模块
    OpenCV学习笔记十九:opencv_gpu*模块
    OpenCV学习笔记十八:opencv_flann模块
    OpenCV学习笔记十七:opencv_bioinspired模块
    OpenCV学习笔记十六:opencv_calib3d模块
  • 原文地址:https://www.cnblogs.com/hao-1234-1234/p/6105521.html
Copyright © 2011-2022 走看看