JS for Loop and PHP loop

Source: Internet
Author: User

Syntax for the FOR loop:

for (initial condition; cyclic condition; state change)

  {alert (attr{i})  }

Instance for (var i=0; i<5; i++) Loop Body   1. Determine the condition first (do not meet the bounce loop)
2. (If conditions are met) perform loop body
3. Status change
Php:
Iterating through an array
1.for Loop traversal
For ($i =0, $i <count ($arr)); $i + +)
{
echo arr{$i}i. " <br> "
}
2.forerch Cycle
The first value of the foreach ($arr) as $v) is V, the loop body
{The second value gives V, the loop body
echo $v. " <br> ",,, ...
}
3.lise () and each () combined traversal

While
List ($k, $v) =each ($arr)
{
echo "{$k}-{$v}<br>"
}
4 pointer traversal

Echo current ($arr); takes the current pointer to the value of the element
echo Key ($arr); takes the current pointer to the index of the element
Next ($arr); Adjust the pointer down
Prev ($arr); Adjust the pointer up
Reset ($arr); Reset the pointer
End ($arr); hit the pointer to the last

Do
{
Current ($arr);
}
while (Next ($arr))

While loop first condition, rear loop body

Do while first loop body, in condition






JS for Loop and PHP loop

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.