Home >Web Front-end >JS Tutorial >JavaScript statement structure

JavaScript statement structure

PHP中文网
PHP中文网Original
2017-06-22 13:44:241464browse

1. Experience

Put the constants on the left side when judging
switch in java only supports four types, and javaScript is a weak type, all of which are supported.

Display method:

               alert("x="+x);
             //将数据直接写到当前页面当中。
              document.write("x="+x+"<br/>");

2. Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=GBK">
        <title>Untitled Document</title>
    </head>
    <body>
        <script type="text/javascript">
            /*
             * 语句:
             * 1,顺序结构。
             *     
             * 2,判断结构。
             *         代表语句: if.
             * 3,选择结构。
             *         switch
             * 4,循环结构。
             *         while  do while  for
             * 5,其他语句。
             *         break:跳出选择,跳出循环。
             *         continue:用于循环语句,结束本次循环继续下次循环。 
             */
            
//            alert("abc1");
//            alert("abc2");
        
        
//            ------------------------------------------------
            /*
            var x = 3;
//            if(x=4){//注意。
            if(4==x){//建议将常量放左边。以报错来修正代码。
                alert("yes");
            }else{
                alert("no");
            }
            
            
            
            if(x>1)
                alert("a");
            else if(x>2)
                alert("b");
            else if(x>3)
                alert("c");
            else
                alert("d");
                
            */    
        
//            ------------------------------------------------
            /*
            //选择结构。
            var x = "abc";
            switch(x){
                
                case "kk":
                    alert("a");
                    break;
                case "abc":
                    alert("b");
                    break;
                default:
                    alert("c");
                    break;//省略。因为是最后一个语句,后面就是大括号了    
            }
            */
            
            
            
            //循环结构。
            /*
            var x = 1;
            document.write("<font color=&#39;blue&#39; >");//颜色控制,html内容
            while(x<10)
            {
//                alert("x="+x);
                //将数据直接写到当前页面当中。
                document.write("x="+x+"<br/>");
                x++;
            }
            document.write("</font>");
            
            
            for(var x=0; x<3; x++){
                document.write("x="+x);
            }
            */
            
            
            /*
            w:for(var x=0; x<3; x++){//标号
                for(var y=0; y<4; y++){
                    document.write("x==="+x);
                    continue w;//跳出当前循环。
                }
            }
            */
            
            
        </script>
        
        
        
        
    </body>
</html>


The above is the detailed content of JavaScript statement structure. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn