zoukankan      html  css  js  c++  java
  • c# 流程控制

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace CSTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("----------1.GOTO----------");
                TestGoTo();
                Console.WriteLine("----------2.三元表达式----------");
                TestThreeExp();
                Console.WriteLine("----------3.IF----------");
                TestIF();
                Console.WriteLine("----------4.SWITCH/CASE----------");
                TestSwitch();
                Console.WriteLine("----------5.CONTINUE----------");
                TestContiune();
                Console.WriteLine("----------6.WHILE----------");
                TestWhile();
                Console.WriteLine("----------7.DOWHILE----------");
                TestDoWhile();
                Console.WriteLine("----------8.FOR----------");
                TestFor();
                Console.WriteLine("----------9.FOREACH----------");
                TestForeach();
                Console.ReadKey();      
            }
            //GOTO语句
            public static void TestGoTo()
            {
                int num = 5;
                goto OutPut;
                num += 10;  //无法访问的代码          
            OutPut:
                Console.WriteLine("Num = " + num);
            }
    
            //三元表达式
            public static void TestThreeExp()
            {
                int num = 5;
                string Msg = num == 0 ? "num = 0" : "num !=0";
                Console.WriteLine(Msg);
            }
    
            //IF 语句
            public static void TestIF()
            {
                if (true)
                {
                    Console.WriteLine("IF 判断结果为True");
                }
                else
                {
                    Console.WriteLine("IF 判断结果非True");
                }
                if (false)
                {
                    Console.WriteLine("IF 判断结果为False");
                }
            }
    
            //Switch case
            public static void TestSwitch()
            {
                string StrSwitch = "C";
                switch (StrSwitch)
                {
                    case "A":
                        Console.WriteLine("Switch A");
                        break;
                    case "B":
                        Console.WriteLine("Switch B");
                        break;
                    case "C":
                        Console.WriteLine("Switch C");
                        break;
                    case "D":
                        Console.WriteLine("Switch D");
                        break;
                    default:
                        Console.WriteLine("Switch Default");
                        break;
                }          
            }
    
            //Contiune
            public static void TestContiune()
            {
                for (int i = 0; i < 10;i++ )
                {
                    if (i < 5) continue;
                    Console.WriteLine("Continue" + i);
                }
            }
    
            //While
            public static void TestWhile()
            {
                int i = 5;
                int count = 5;
                while (i < 10)
                {              
                    count++;
                    Console.WriteLine("While 执行次数" + count + "; i = " + i);
                    i++;
                }
            }
    
            //DoWhile
            public static void TestDoWhile()
            {
                int i = 5;
                int count = 0;
                do
                {
                    count++;
                    Console.WriteLine("While 执行次数" + count + "; i = " + i);
                    i++;
                } while (i < 10);
            }
    
            //FOR
            public static void TestFor()
            {
                for (int i = 0; i < 3; i++)
                {
                    Console.WriteLine("i = " + i);
                    i++;
                }
            }
    
            public static void TestForeach()
            {
                int[] Arr_i = new int[] { 1, 2, 3, 5 };
                foreach (int i in Arr_i)
                {
                    Console.WriteLine("i = " + i);
                }
            }
        }
    }
  • 相关阅读:
    Codeforces 812E Sagheer and Apple Tree
    bzoj 4765: 普通计算姬
    bzoj 4552: [Tjoi2016&Heoi2016]排序
    bzoj 1096: [ZJOI2007]仓库建设
    bzoj 1030: [JSOI2007]文本生成器
    bzoj 1095: [ZJOI2007]Hide 捉迷藏
    JS实现HashMap
    A4纸表格打印
    JAVA字符串格式化-String.format()的使用
    证书打印CSS知识点总结
  • 原文地址:https://www.cnblogs.com/skyloverdan/p/5849648.html
Copyright © 2011-2022 走看看