zoukankan      html  css  js  c++  java
  • Javascript之四

    流程控制:

      赋值语句: var varible=30;

                       var varible="学习Javascript”;

                       var varible=false;

      if语句: if(expression){

                       statement1

                      }else{

                       statement2

                       }

        if语句嵌套: var m=12,n=m;

                        if(m<1){

                           if(n==1)

                              alert("判断m小于1,n等于1");

                            else

                              alert("判断m小于1,n不等于1");

                       }else if(m>10){

                            if(n==1)

                               alert("判断m大于10,n等于1");

                          else

                              alert("判断m大于10,n不等于1"); 

                          }

          Switch语句:多路分支语句

                     switch(expression){

                     case judgment 1:

                            statement 1;

                            break;

                     case judgment 2:

                            statement 2;

                            break;

            ...

                     case judgement n:

                            statement n;

                            break;

                     default:

                            statement n+1;

                            break;循环控制语句:while语句、do...while语句、for循环

                     while语句: while(expression){

                                       statement

                                       }

                     do...while语句:  do{

                                         statement

                                          } while(expression);

                      for循环:  for(initialize;test;incresment){

                                    statement

                                     }

    跳转语句:

                       continue语句:var total=0;

                                          var sum=new Array(1000,1200,100,600,736,1107,1205);

                                          for(i=0;i<sum.length;i++){

                                          if(sum[i]<1000)continue;

                                          total+=sum[i];

                                          }

                                          document.write("累加和为:"+total);

                       break语句: var sum=0;

                                       for(i=0;i<100;i++){

                                             sum+=i

                                             if(sum>10) break;

                                           }

                                        document.write("0至"+i+"(包括"+i+")之间自然数的累加和为:“+sum);

  • 相关阅读:
    [题解] P2513 [HAOI2009]逆序对数列
    [题解]洛谷P2709 小B的询问
    题解 P1944 最长括号匹配_NOI导刊2009提高(1)
    [题解]SP703 SERVICE
    Bzoj2427: [HAOI2010]软件安装
    【题解】UVA11362 Phone List
    【题解】P2922 [USACO08DEC]秘密消息Secret Message
    Tire树的学习
    【题解】P1171 售货员的难题
    计算机与编程资源教程汇总
  • 原文地址:https://www.cnblogs.com/hjzou/p/4854571.html
Copyright © 2011-2022 走看看