条件语句

if else

同js一样,支持if else,如下例子

  1. <%
  2. var a =true;
  3. var b = 1;
  4. if(a&&b==1){
  5. }else if(a){
  6. }else{
  7. }
  8. %>

switch-case

同js一样,支持switch-case,如下例子

  1. <%
  2. var b = 1;
  3. switch(b){
  4. case 0:
  5. print("it's 0");
  6. break;
  7. case 1:
  8. print("it's 1");
  9. break;
  10. default:
  11. print("error");
  12. }
  13. %>

switch变量可以支持任何类型,而不像js那样只能是整形

select-case

select-case 是switch case的增强版。他允许case 里有逻辑表达式,同时,也不需要每个case都break一下,默认遇到合乎条件的case执行后就退出。

  1. <%
  2. var b = 1;
  3. select(b){
  4. case 0,1:
  5. print("it's small int");
  6. case 2,3:
  7. print("it's big int");
  8. default:
  9. print("error");
  10. }
  11. %>

select 后也不需要一个变量,这样case 后的逻辑表达式将决定执行哪个case.其格式是

  1. <%
  2. select {
  3. case boolExp,orBoolExp2:
  4. doSomething();
  5. }
  6. %>
  1. <%
  2. var b = 1;
  3. select{
  4. case b<1,b>10:
  5. print("it's out of range");
  6. break;
  7. case b==1:
  8. print("it's 1");
  9. break;
  10. default:
  11. print("error");
  12. }
  13. %>