zoukankan      html  css  js  c++  java
  • ECMAscript之if..else语句,for循环,while循环,switch,case语句,异常处理

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>if else语句</title>
    </head>
    <body>
    <script>
    // 1.if else语句
    // a='star';
    // if(a=='star'){
    // alert('ok');
    // }else{
    // alert('no');
    // }
    //2.if else语句
    // a='star';
    // if(a=='star') {
    // alert('ok');
    // }else if(a=='sun'){
    // alert('no');
    // }else{
    // alert('123');
    //}
    //3.switch case 语句
    // var x=3;
    // switch (x){
    // case 1:y='lai';break;
    // case 2:y='tong';break;
    // case 3:y='xing';break;
    // default:y='none';
    // }
    // alert(y)
    //4.for循环控制语句1
    // var a=[1,true,'star']
    // for(var i in a){
    // console.log(i);
    // console.log(a[i]);
    // }
    //for循环控制语句2
    // for(var i=0;i<=5;i++){
    // console.log(i);
    // }
    //(2)
    // var sum=0;
    // for(var i=1;i<=100;i++){
    // sum+=i;
    // }
    // alert(sum);5050
    // (3) for(var i=1;i<=6;i++){
    // document.write('<h'+i+'>hello</h'+i+'>')
    // document.write('<br>')
    // }
    // obj={"1":"star","2":['lat',1,"2"]}
    // alert(typeof(obj))//object
    // alert(obj);//[object Object]
    // for(var i in obj){
    // console.log(i);
    // console.log(obj[i]);
    // }
    //5 .while循环
    //1+2+.....100
    // var i=1,sum=0;
    // while (i<=100){
    // sum+=i;
    // i++;
    // }alert(sum)
    //6.异常处理
    // (1)try{
    //
    // }catch(e){
    //
    // }
    // finally {
    //
    // }
    //(2)主动抛出异常
    // throw Error('error')

    </script>

    </body>
    </html>
  • 相关阅读:
    HDU 6071
    HDU 6073
    HDU 2124 Repair the Wall(贪心)
    HDU 2037 今年暑假不AC(贪心)
    HDU 1257 最少拦截系统(贪心)
    HDU 1789 Doing Homework again(贪心)
    HDU 1009 FatMouse' Trade(贪心)
    HDU 2216 Game III(BFS)
    HDU 1509 Windows Message Queue(队列)
    HDU 1081 To The Max(动态规划)
  • 原文地址:https://www.cnblogs.com/startl/p/12234874.html
Copyright © 2011-2022 走看看