关注我的动态
using System.Diagnostics.Tracing; namespace _13.语句 { internal class Program { static void Main(string[] args) { //1.赋值语句 int a = 1; //2.表达式语句 bool b = 1 > 2; //3.块语句 { int c = 1; string d = "hello"; } //4.if语句 if (1 > 0) { } //5.if else 语句 if (1 > 0) { } else { } //6.if elseif ..else 语句 int e = 90; if (e >= 90) { } else if (e >= 80) { } else if (e >= 60) { } else { } //for语句 int[] f = { 1, 2, 3, 4, 5, 6 }; var i = 0; for (i = 0; i < f.Length; i++) { int tem = f[i]; } //foreach迭代语句 foreach (var item in f) { int tem = item; } //while语句 i= 0; while (i < f.Length) { int tem = f[i++]; } //do...while语句 i = 0; do { int tem = f[i++]; } while (i < f.Length); //switch语句 string abc = "1"; switch (abc) { case "1": abc += "1"; break; case "2": abc += "2"; break; case "3": abc += "3"; break; default: break; } //continue语句 for (i = 0; i < f.Length; i++) { if (i % f.Length == 1) { continue;//跳过 } Console.WriteLine(f[i]); } //break语句 for (i = 0; i < f.Length; i++) { if (i > 3) { break;//退出循环 } Console.WriteLine(f[i]); } //goto语句 i = 0; Loop: if (i++<10) goto Loop; //方法调用语句 Console.WriteLine("Hello World!!!"); } } }