for loop in Jav...LOGIN

for loop in JavaScript

for loop

Format:

for(variable initialization ; Conditional judgment; Variable update)

{

Loop body code;

}

5.png

Example: Find 100 The sum of numbers that are divisible by 10

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            var sum = 0; 
            for(var i=1;i<=100;i++){
                if(i%10==0){
                    sum+=i;
                }
            }
            document.write("100以内能被10整除的数之和为:"+sum)
        </script>
    </head>
    <body>
    </body>
</html>


Next Section
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var sum = 0; for(var i=1;i<=100;i++){ if(i%10==0){ sum+=i; } } document.write("100以内能被10整除的数之和为:"+sum) </script> </head> <body> </body> </html>
submitReset Code
ChapterCourseware