Asp.netC#

C#流程控制语句

字号+ 作者:hanyufeng 来源: 2009-06-20 15:11:11 我要评论( ) 阅读:

C 流程控制语句...

一、布尔逻辑
    1、==(等于),!=(不等于),<(小于),>(大于),<=(小于等于),>=(大于等于)
    2、!(非),&(与),|(或),^(两个仅有一个为真),&&(与),||(或)
    3、布尔赋值运算符:&=,|=,^=
    4、位移运算符:>>=,<<=
二、分支结构
    1、三元运算符:<test>?<resultIfTrue>:<resultIfFalse>
    2、分支语句:
      (1)IF语句:
                   if(<test>   
                   {
                         <code executed>;
                   }
                   else
                   {
                         <code executed>;
                   }
       (2)switch语句:
                 switch(<testVar>)
                 {
                      case<comparisonVal1>
                      {
                         <code executed>;
                         break;
                      }
                      case<comparisonVal2>
                      {
                         <code executed>;
                         break;
                      }
                      ......                                   
                      case<comparisonValN>
                      {
                         <code executed>;
                         break;
                      }
                      default:
                      {
                         <code executed>;
                         break;
                      }
                 }
    4、do循环:
              do
              {
                   <code>;
               }while(<test>;
    5、while循环:   
                   while(<test>
                   {
                       <code>; 
                   }
    6、for循环: 
                for(<initialization>;<condition>;<operation>)
                {
                    <code>;
                }
    7、循环的中断:
       break:中止循环,执行循环语句以下的代码(离开循环体)
       continue:跳出当前循环并进入下一次循环(仍在循环体内)
       return:中止循环并跳出循环所在的函数(离开循环体,也离开所在的函数)

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。