The loop in the JS scripting language

Source: Internet
Author: User

JS scripting language: Looping: (Looping through a function (executing a piece of code))

Four elements: Cyclic initial value cyclic condition state change loop body

for (exhaustive iteration)

While

Example: (exhaustive) with 7-related numbers

<script type= "Text/javascript" >

var s= "";

for (Var i=0;i<100;i++)

{if (i%7==0| | i%10==7| | Pareint (i%10==7)

{

s=s+i+ "|"

}

} alert (s);

(iteration) 100 The sum of the inner numbers

var sum=0;

for (Var i=0;i<100;i++)

{

Sum=sum+i; (sum+=i)

} alert (sum);

Basketball fell from five meters, each bounce height is the original 30%, after several heights of 0.1m

var g=5; var c=0;

while (true)

{

g=g*0.3;c++;

if (g<0.1)

{break;

}

} alert (c);

</script>

The loop in the JS scripting language

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.