c#基础【四】流程控制语句

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Base04
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("请输入一个数字:");
            //int a = Int32.Parse(Console.ReadLine());
            //if(输入的永远是比较运算符)
            //if(bool型) 当条件满足时则执行当前代码块      else 当条件不满足时则执行当前代码块
            //if (a > 0)
            //{
            //    Console.WriteLine("输入的数字大于0");
            //}
            //else
            //{
            //    Console.WriteLine("输入的数字小于0或者等于0");
            //}

            //else if 多重
            //Console.WriteLine("请输入一个数字");
            //int a = Int32.Parse(Console.ReadLine());
            //if(判断的第一个文件)  如果满足第一个条件则后续的所有的代码块不执行
            //else if(判断的第N个) else if   可以出现N次,满足条件则其余的判断则不会执行
            //else  完全不满足当前的  if 和 else if里面的所有的条件判断
            //if (a > 0)
            //{
            //    Console.WriteLine("输入的数字大于0");
            //}
            //else if(a == 0)
            //{
            //    Console.WriteLine("输入的数字等于0");
            //}
            //else
            //{
            //    Console.WriteLine("输入的数字小于0");
            //}

            //嵌套if
            //飞机票分为经济舱和头等舱
            //旺季和淡季
            //Console.WriteLine("1代表经济舱,2代表头等舱");
            //int index = Int32.Parse(Console.ReadLine());
            //if (index == 1)
            //{
            //    Console.WriteLine("请输入月份:");
            //    int m = Int32.Parse(Console.ReadLine());//提示快捷键Ctrl+j
            //    if (m > 4 && m < 11)
            //    {
            //        Console.WriteLine("经济舱+旺季");
            //    }
            //    else
            //    {
            //        Console.WriteLine("经济舱+淡季");
            //    }
            //}
            //else
            //{
            //    Console.WriteLine("请输入月份:");
            //    int m = Int32.Parse(Console.ReadLine());//提示快捷键Ctrl+j
            //    if (m > 4 && m < 11)
            //    {
            //        Console.WriteLine("头等舱+旺季");
            //    }
            //    else
            //    {

            //        Console.WriteLine("头等舱+淡季");
            //    }
            //}

            //switch语句
            //Console.WriteLine("请输入一个月份:");
            //int m = Int32.Parse(Console.ReadLine());
            //switch (m)
            //{
            //    case 1:
            //        Console.WriteLine(m);
            //        break;
            //    case 2:
            //        Console.WriteLine(m);
            //        break;
            //    case 3:
            //        Console.WriteLine(m);
            //        break;
            //    case 4:
            //        Console.WriteLine(m);
            //        break;
            //    default:
            //        Console.WriteLine("错误");//5
            //        break;
            //}

            //Console.WriteLine("请输入一个月份:");
            //int M = Int32.Parse(Console.ReadLine());//包含类型整数/字符类型/枚举类型
            //switch (m)
            //{
            //    case 1://满足所有的条件    由于它执行的是同一个效果就可以写case代码块
            //    case 2://当其中有一个输出的内容不是同一个就需要散开写
            //    case 3:
            //    case 4:
            //    case 5:
            //    case 6:
            //    case 7:
            //    case 8:
            //    case 9:
            //    case 10:
            //    case 11:
            //    case 12:
            //        Console.WriteLine("当前的月份是{0}",M);//输出的是下标
            //        break;//终止
            //    default:
            //        Console.WriteLine("错误");
            //        break;
            //}

            //死循环
            //循环的条件的值   也是bool类型    条件成立则执行循环体  条件不成立则退出
            //while 先判断 后执行 偏高  行
            //while (true)
            //{
            //    Console.WriteLine("1");
            //}

            //输出0-100
            //int index = 0;
            //while (index<101)
            //{
            //    Console.WriteLine(index);//死循环
            //    index++;//递增1完成循环   100
            //}

            //int index = 0;
            //while (index < 101)
            //{
            //    index++;//递增1完成循环   101
            //    Console.WriteLine(index);//死循环
            //}

            //do.....while(循环条件);   先执行  后判断    无
            //do
            //{
            //    Console.WriteLine("1");
            //} while (true);
            //int index = 0;
            //do
            //{
            //    Console.WriteLine(index);
            //    index++;
            //} while (index<=10);

            //for(开始的位置:判断的条件:叠加(++)或者递减(--))
            //for (;;)
            //{
            //    Console.WriteLine("1");
            //}
            //第一次执行的时候,是不进入叠加或者递减
            //第二次开始
            //for(int index = 0; index < 10; index++)
            //{
            //    Console.WriteLine(index);
            //}

            //for(int i = 0; i < 11; i++)
            //{
            //    if (i > 4)
            //    {
            //        break;//终止后续所有的操作
            //    }
            //    Console.WriteLine(i);//01234
            //}
            //for (int i = 0; i < 11; i++)
            //{
            //    if (i > 4)
            //    {
            //        Console.WriteLine(i);//5678910
            //    }
            //}

            //continue
            //for(int i = 0; i <= 10; i++)
            //{
            //    if (i < 4)
            //    {
            //        continue;//退出当前循环
            //    }
            //    Console.WriteLine(i);//5678910
            //}

            //return
            //for(int i = 0; i <11; i++)
            //{
            //    if (i==4)
            //    {
            //        return;//返回的循环外
            //    }
            //    Console.WriteLine(i);
            //}





            //1.小强参加Java考试,爸爸答应他如下条件:(多重if)
            //    成绩 >= 90 :送奔驰轿车
            //    成绩 >= 80 :送奥迪轿车
            //    成绩 >= 60 :送比亚迪F0
            //    成绩 < 60  :送一个耳光
            //Console.WriteLine("请输入小强的java考试成绩:");
            //double d = Double.Parse(Console.ReadLine());
            //if (d >= 90)
            //{
            //    Console.WriteLine("送奔驰轿车");
            //}
            //else if(d>=80)
            //{
            //    Console.WriteLine("送奥迪轿车");
            //}
            //else if (d>=60)
            //{
            //    Console.WriteLine("送比亚迪F0");
            //}
            //else
            //{
            //    Console.WriteLine("送一个耳光");
            //}


            //2.机票预定:实际机票价格 原价为4000元(嵌套if)
            //    5 - 10月为旺季,头等舱打9折,经济舱打7.5折
            //    其余时间为淡季,头等舱打6折,经济舱打3折
            //Console.WriteLine("请输入您要买的飞机票是头等舱还是经济舱:");
            //string a = Console.ReadLine();
            //if (a == "头等舱")
            //{
            //    Console.WriteLine("请输入月份:");
            //    int i = Int32.Parse(Console.ReadLine());
            //    if (i >= 5 && i <= 10)
            //    {
            //        double b = 4000;
            //        Console.WriteLine("旺季的头等舱的价格为:" + b * 0.9 + "元");
            //    }
            //    else
            //    {
            //        double b = 4000;
            //        Console.WriteLine("淡季的头等舱的价格为:" + b * 0.6 + "元");
            //    }
            //}
            //else if (a == "经济舱")
            //{
            //    Console.WriteLine("请输入月份:");
            //    int i = Int32.Parse(Console.ReadLine());
            //    if (i >= 5 && i <= 10)
            //    {
            //        double b = 4000;
            //        Console.WriteLine("旺季的经济舱的价格为:" + b * 0.75 + "元");
            //    }
            //    else
            //    {
            //        double b = 4000;
            //        Console.WriteLine("淡季的经济舱的价格为:" + b * 0.3 + "元");
            //    }
            //}
            //else
            //{
            //    Console.WriteLine("请输出您要购买的飞机票类型");
            //}


            //3.输入一个月份, 打印出该月的天数(switch)
            //  月份: 4,6,9,11 小月 1,3,5,7,8,10,12 大月
            //Console.WriteLine("请输入一个月份:");
            //int a = Int32.Parse(Console.ReadLine());
            //switch (a)
            //{
            //    case 4:
            //    case 6:
            //    case 9:
            //    case 11:
            //        Console.WriteLine(a + "月" + "30天");
            //        break;
            //    case 1:
            //    case 3:
            //    case 5:
            //    case 7:
            //    case 8:
            //    case 10:
            //    case 12:
            //        Console.WriteLine(a + "月" + "31天");
            //        break;
            //    default:
            //        Console.WriteLine("请输入正确的月份");
            //        break;
            //}


            //4.循环输出10到100之间所有能被5整除的数(while)。
            //int a = 10;
            //while (a <= 100)
            //{
            //    a++;
            //    if (a % 5 == 0)
            //    {
            //        Console.WriteLine(a);
            //    }
            //}

            //5.计算1 + 2 + 3 +……+100的结果(do...while)
            //int a = 1;
            //int b = 0;
            //do
            //{
            //    b = a + b;
            //    a++;

            //} while (a <= 100);
            //{
            //    Console.WriteLine(b);
            //}

            //6.从1一直加到100,但如果累加的和于500也要结束循环,并输出此时已经加到的数是什么(for)
            //int count = 0;
            //for (int i = 1; i <= 100; i++)
            //{
            //    count = i + count;
            //    if (count > 500)
            //    {
            //        Console.WriteLine("当前相加到的数值是:" + i);
            //        break;
            //    }
            //}
            //Console.ReadKey();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值