JS Essay 4

Source: Internet
Author: User

After these days, JS also came to the interesting place, our goal is what? Lazy! So let's start with the Loop statement:

Looping statements


while (exp) {

while (variable <= end value) {code to be executed}

 // while    output 1000 digits from 1 to 1000  var  i =1  ;  while  (I<1001   + '   '   '   (I%10  ==0   "  <br/>    )//Here The IF statement controls the conditions for line breaks, the same as} i

We can also control only the output of odd books or even numbers:

//only to lose the odd numbervari =1; while(i<1001){    if(i%2!=0) {document.write (i+' ')    }    if(i% -==0) {document.write ('<br/>')} I++}


do {
}while (condition);

Do {code to be executed} while (variable <= end value)

var i=1;  Do {    document.write (i);     if (i%=0) {        document.write ('<br/>' ) )    }    I+ +;}  while (i<1001);

Ps:while and do...while The difference is not difficult to see, is to first judge or execute first.

3.for Loop statement

The For statement is the most commonly used loop statement, and the following is the basic syntax:

for (initial; expression; post-loop-expression) {

for (variable = start value; variable <= end value; variable = variable + step value) {
Code to be executed

 for (var1; i <i++) {    document.write (' '+i+'. jpg '/>');} // It is important to note that the address of the image is relative to the HTML, and the splicing function of the +

Break statements and Continue statements

The break statement can exit the loop immediately;
The continue statement simply exits the current loop;

//Break Statementvarn=o; for(varI=1;i<Ten; i++){     if(i>5){            Break; } N++;} alert (n);//Continue statementsvarn=0; for(var=1;i<Ten; i++){    if(i==4){        Continue; } N++;} Ducument.write (n);

PS: The execution process of the program is generally carried out according to the process from top to bottom, and if it is not, the code is not executed; the switch does not conform to the case, and the code snippet is generally not executed; The loop body in the FOR Loop statement automatically loops as long as the condition is set.

JS Essay 4

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.