• 语句,分支


    using System.Formats.Asn1;

    namespace MyFirstConsoleApp
    {
    internal class Program
    {
    static void Main(string[] args)
    {
    TryAnIF();
    TryAnIfElse();
    TrySomeLoops();
    }
    ///
    /// 要点
    ///
    ///
    /***
    *不要忘记所有语句都要以一个分号结束
    *行首使用两个斜线为代码增加注释
    *声明变量时要提供一个类型,后面是一个名字
    *大多数情况下,可以有额外空白符
    *if/else、while、do和for都要测试条件
    ***/
    private static void TryAnIF()
    {
    int someValue = 4;
    string name = “Bobbo Jr.”;
    if ((someValue == 3) && (name == “Joe”))
    {
    Console.WriteLine(“x is 3 and the name is Joe”);
    }
    Console.WriteLine(“this line runs no matter what”);
    }

        private static void TryAnIfElse()
        {
            int x = 5;
            if (x == 10)
            {
                Console.WriteLine("x must be 10");
            }
            else
            {
                Console.WriteLine("x isn't 10");
            }
        }
    
        private static void TrySomeLoops()
        {
            int count = 0;
    
            while (count < 10)
            {
                count = count + 1;
            }
            for (int i = 0; i < 5; i++)
            {
                count = count - 1;
            }
            Console.WriteLine("The answer is " + count);
        }
    
    
        private static int area;
        private static int height;
        private static int width;
    
        static void Main(string[] args)
        {
            OperatorExamples();
        }
    
        private static void OperatorExamples()
        {
            Console.WriteLine(area);
    
            while (area < 20)
            {
                height++;
                area = width * height;
    
            }
            do
            {
                width--;
                area = width * height;
            } while (area > 25);
            //This statement declares a variable and sets it to 3
            int width = 3;
            //The == operator increments a variable (adds 1 to 3)
            width++;
    
            //Declare two more int variables to hold numbers and
            //use the + and * operators to add and multiple values
            int height = 2 + 4;
            int area = width * height;
            Console.WriteLine(area);
    
            //The next two statements declare string variables
            //and use + to concatenate them (join them together)
            string result = "The area";
            result = result + " is " + area;
            Console.WriteLine(result);
    
            //A Boolean variable is either true or false
            bool truthValue = true;
            Console.WriteLine(truthValue);
    
            //“if”语句做决策
            int someValue = 10;
            string message = "";
            if (someValue == 24)
            {
                message = "Yes,it' 24!";
            }
    
            //if/else语句在条件不为真时也会做些事情
            if (someValue == 24)
            {
                message = "Yes,it' 24!";
            }
            else
            {
                message = "The value wasn't 24.";
            }
    
            //while循环就是当条件为true时循环执行语句
            int x = 10;
            while (x > 5)
            {
    
            }
    
            //do/while循环先运行语句再检查条件
            do
            {
    
            } while (x > 5);
    
            //for循环在每次循环后运行一个语句
            for (int i = 0; i < 8; i = 1 + 2)
            {
    
            }
    
            LOOP#1
            int count = 5;
            while (count > 0)
            {
                count = count * 3;
                count = count * -1;
            }
    
            LOOP #2
            int j = 2;
            for (int i = 1; i < 100; i = i * 2)
            {
                j = j - 1;
                while (j < 25) //执行7次
                {
                    //下一个语句会执行多少次?
                    j = j + 5; //执行6次
                }
            }
    
            //LOOP #3
            int p = 2;
            for (int q = 2; q < 32; q = q * 2)
            {
                while (p < q) //执行10次
                {
                    p = p * 2;//执行3次
                }
                q = p - q;
            }
    
            LOOP #4
            int i = 0;
            int count = 2;
            while (i == 0)//死循环
            {
                count = count * 3;
                count = count * -1;
            }
    
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153

    }
    }

  • 相关阅读:
    【大数据实训】基于Hadoop的2019年11月至2020年2月宁波天气数据分析(五)
    什么是简单网络管理协议(SNMP)
    Beats:介绍 Filestream fingerprint 模式
    计算机毕业设计ssm大学生比赛信息管理系统38iiq系统+程序+源码+lw+远程部署
    大二学生JavaScript实训大作业——动漫秦时明月7页 期末网页制作 HTML+CSS+JavaScript 网页设计实例 企业网站制作
    Node.js 入门教程 1 Node.js 简介
    【Machine Learning】14.Advanced Learning 简单神经网络介绍(1)
    【动手学深度学习-Pytorch版】门控循环单元GRU
    Spring中Bean的作用域和生命周期
    redis持久化之AOF(Append Only File)
  • 原文地址:https://blog.csdn.net/qq_40418109/article/details/126843989