第一天

来源:互联网 发布:淘宝企业店铺 个体户 编辑:程序博客网 时间:2024/05/22 17:43

今天跟着老师巩固了一些过去所学基础知识 其中 我以前对于while的循环语句很是不能玩转 经过了今天

的复习 终于整明白了 但是还是习惯用for语句 觉得whlie用起来别扭 下面是我跟着老师写的一段whlie

语句的代码
       Console.WriteLine("输入一个数");
            string str = Console.ReadLine();
            int max = Convert.ToInt32(str);

            int temp = 0;
            Console.WriteLine("输入一个数");
            string input = Console.ReadLine();
            while (input != "end")
            {
                temp = Convert.ToInt32(input);
                if (temp > max)
                {
                    max = temp;
                }
                Console.WriteLine("输入一个数");
               input= Console.ReadLine();
            }
            Console.WriteLine(max);
下一个是规定while(true)的代码 虽然达到的效果和上面一样 但是经过对于条件的改动 代码也发生了

变化     Console.WriteLine("输入一个数");
       string str = Console.ReadLine();
       int max = Convert.ToInt32(str);
            int temp = 0;
 while (true)
            {
                Console.WriteLine("输入一个数");
               string input = Console.ReadLine();
               
              if (input == "end")
               {
                  break;
              }
                  temp=Convert.ToInt32(input);
                   
              if(temp>max)
                {
                    max = temp;
                }
              
            }
             Console.WriteL

原创粉丝点击