定义:描述某个类型或让程序执行某个动作的源代码指令
语句种类:
空语句仅由一个分号组成 → ;
条件执行语句
循环语句
跳转语句
条件执行和循环结构需要一个测试表达式或条件以决定程序应当在哪里继续执行
if(x<=10) → if 语句 z=x-1; //简单语句不需要大括号 if(x<=10){ → if..else语句 z = x-1; }else{ z =x; } switch(x){ →Switch..case case 10: z = x-1; break; default: z=x; break; }
while(true){} →死循环 int x = 1; int z = 0; while(x<10){ →while循环 z +=x; x++; } do{ z +=x; x++; }while(x<20) for(int i = 0;i<10;i++){ →for循环 x +=i; } int[] array = new int[]{1,2,3}; →foreach循环 foreach(var item in array){ x +=item }
int x= 0; while(true){ → break语句 x++; if(x==10){ break; } } for(int i =0;i<10;i++){ if(i%2==0){ Console.WriteLine(i); }else{ continue; →continue; } } while(true){ if(x>10){ goto end; //goto 语句配标签语句 } } end:Console.WriteLine("跳出循环")
目的;使用using语句可以更加合理的控制资源的调用和释放
组成部分:
using语句可以多个资源嵌套
原文:https://www.cnblogs.com/FrameCode/p/15027133.html