LEARN JAVASCRIPT QUICKLY AND JAVASCRIPT CODING EXERCISES: Coding For Beginners by TAM JJ

LEARN JAVASCRIPT QUICKLY AND JAVASCRIPT CODING EXERCISES: Coding For Beginners by TAM JJ

Author:TAM, JJ [TAM, JJ]
Language: eng
Format: epub
Published: 2020-12-24T00:00:00+00:00


JavaScript: for loop

The for statement provides a compact way to iterate over a range of values.

Syntax

for(initialization; condition; update){

//statements to be executed

}

for loop execute the statements until the condition evaluates to false.

a . Initialization section executed only once, at the starting of loop.

b . Condition section evaluated every time, before executing the loop statements

c . update section executes immediately after every execution of loop finishes.

for.html

<!DOCTYPE html>

<html>

<head>

<title> for loop </title>

</head>

<body>

<script type= "text/javascript" >

var number = parseInt (prompt( "Enter a number" , "10" ));

document .write( "<h2>Even numbers from 0 to " + number + " are </h2>" );

for ( var i = 0 ; i <= number; i += 2 ) {

document .write(i + "<br />" );

}

</script>

</body>

</html>

Load above page in browser, it prompts for a number, and print all the even numbers from 0 to the number given by user.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.