.Net基础篇_学习笔记_第五天_流程控制while循环002
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 流程语句02 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 14 string anwer= ""; 15 int i = 1; 16 while (anwer != "yes" && i <= 10) 17 { 18 Console.WriteLine("你们会了么?yes/no?这已经是讲的第{0}遍了", i); 19 anwer = Console.ReadLine(); 20 if (anwer == "yes") 21 { 22 Console.WriteLine("既然会了,可以放学啦!"); 23 break; 24 } 25 i++; 26 } 27 while (i > 10) 28 { 29 Console.WriteLine("老师都已经讲了第{0}遍了,你们不会也放学吧!",i); 30 break; 31 } 32 Console.ReadKey(); 33 34 } 35 } 36 }
练习二:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 流程语句02 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 double person = 80000; 14 int year = 2006; 15 while (person < 200000) 16 { 17 person *= 1.25; 18 year++; 19 } 20 Console.WriteLine("在{0}年,人数超过200000人",year); 21 Console.ReadKey(); 22 23 } 24 } 25 }