If loop statements in JavaScript

Source: Internet
Author: User

<meta charset= "UTF-8" >
<title></title>
<script type= "Text/javascript" >
/*
* Output consecutive digits to the page
*/
document.write (1);
var n=1;
document.write (n++ + "<br/>");
/*
* Loop statement:
* Repeated execution of a piece of code multiple times through a looping statement
* While loop:
* Syntax: \
* while (conditional expression) {
* Statement ...
*
* }
* While statements are executed,
* Evaluate the expression of the day sword first
* If the value is true, the loop body is executed,
* After the completion of the loop body, continue to judge the expression
* If true, resumes execution of the loop body and so on
* Terminates the loop if the value is Fasle
*/
/*
* while (true) {
* Alert (n++);
* }
* A loop like this that writes a conditional expression to true, called a dead loop
* The loop will not stop unless the browser is closed and the dead loop is used with caution in development
* You can use break to terminate the loop
*
*/
1. Create a variable to initialize
var i = 0;
2. Set a conditional expression in a loop
while (I&LT;10) {
alert (i);
i++
3. Define an update expression, each time the initialization variable is updated
}
/*
* Do...while cycle,,
* Grammar
* do{
* Statement ...
*}while (conditional expression);
* Execution Process:
* Do...while statement executes, the loop body is executed first,
* After the completion of the loop body, the conditional expression after the while is judged
* If the result is true, continue execution of the loop body, after execution, continue to judge and so on
*
* Actually these two statements function similarly, the difference is that the while is the first to judge after the execution
* and Do...while will be executed first and then judged
* Do...while can ensure that the loop body is executed at least once
* While not
*/
do{
document.write (i++ + "<br/>");
}while (i <= 10);
//
</script>
<body>
</body>

If loop statements in JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.