if 、whitch、for、while


if 用于过程的判断  whitch用于值得判断  

if

else if

else if //当此前的过程满足条件时,程序便不再判断其他过程,但是if{}if{}这样的写法程序会将每个过程判断一遍,降低了程序执行效率

else

whitch()//括号里面写变量名

 case 值1:

          表达式1;

break;

case 值2:

          表达式2;

break;

default:

表达式3;

break;

for:重复做某一件事,循环次数确定

1.确定循环次数2.参数初始化3.改变循环条件

class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine($"这是第{i+1}老婆!!");
            }
            Console.ReadLine();
        }
    }

乘法表的打印(平面打印一般用两重for循环):

 class Program
    {
        static void Main(string[] args)
        {
            for (int a = 1; a <=9; a++)
            {
                for (int b = 1; b <= a; b++)
                {
                    Console.Write($"{a}*{b}={a*b}\t");

                }
                Console.WriteLine("\n");
            }
            Console.ReadLine();
        }
    }

 三角新的打印

 class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i<=5; i++)//控制行数
            {
                for (int a = 1; a <= 5-i; a++)//打印空白
                {
                    Console.Write(" ");//此处引号里面有空格,""和" "在C#中是不一样的字符串
                }
                for (int a = 1; a <= 2*i-1; a++)//打印空白
                {
                    Console.Write("$");//因为喜欢钱,所以用美元符号
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }

 while 重复做某件事情的次数不一定,也可以一次不做

Console.WriteLine("你以前的时间:");
            int times = int.Parse(Console.ReadLine());
            while (times < 3)
            {
                Console.WriteLine("时间不行,多吃韭菜!!");
                Console.WriteLine("---------------------");
                times = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("时间合格!");
            Console.ReadLine();

 do-while 重复做某件事情的次数不一定,至少做一次(先做后判断)

  Console.WriteLine("请输入这个月做的次数:");
            int times = int.Parse(Console.ReadLine());
            do
            {
                Console.WriteLine("强制做了一次!");
                times = int.Parse(Console.ReadLine());
            }
            while (times <3);
            
                Console.WriteLine("已经做了三次,可以了!!");
            
            Console.ReadLine();

 break 跳出整个循环

 for (int i = 0; i < 20; i++)
            {
                Console.WriteLine($"只是你的第{i}次");
                Console.WriteLine("还能坚持吗?");
                if (Console.ReadLine() == "n")
                {
                    Console.WriteLine("你不行了,Game Over!!");
                    break;
                }
                Console.WriteLine("牛逼!!");
               
            }
            Console.ReadLine();

 continue  重复过程中,条件不满足则跳出当前循环,进行下一个循环

 
            int i=0;
            while (i<5)
            {
                Console.WriteLine("大王您看这妃子咋样??");
                string minds = Console.ReadLine();
                if (minds != "满意")
                    continue;
                i++;
                Console.WriteLine("已收入后宫!!");
            }
            Console.WriteLine("后宫已满!!");
            Console.ReadLine();