| You are here: DEVPPL ‹ Forum ‹ Programming ‹ PHP and MySQL Forum ‹ Script-archive |
NOTIFICATIONS
|
|
|||||||||||||||
Login |
For Loop Example
1 post
• Page 1 of 1
0
For Loop Example
This is just a quick bit to show how to use a for loop in PHP
The For Loop Syntax.
It is actually really simple
What happens during the code execution is that at the beginning, it runs the variable declaration code first, then it checks the condition statement( like an if statement), and if it is true, than it runs through the block of code(whats in between the brackets), and finally it calls the increment code.
Unfortunately, in PHP the for loop is LESS efficient than the foreach loop, which is the complete opposite when compared to most programming languages, such as c, c++, c#, and so on.
well i hope that shows you guys some of the basics
- Code: Select all
<?php
$string = "Hello World";
$length = strlen($string);
for($i = 0; $i < $length; $i++)
{
echo $string[$i].'<br />';
}
?>
The For Loop Syntax.
It is actually really simple
- Code: Select all
for(VARIABLE DECLARATION; CONDITION; INCREMENT)
What happens during the code execution is that at the beginning, it runs the variable declaration code first, then it checks the condition statement( like an if statement), and if it is true, than it runs through the block of code(whats in between the brackets), and finally it calls the increment code.
Unfortunately, in PHP the for loop is LESS efficient than the foreach loop, which is the complete opposite when compared to most programming languages, such as c, c++, c#, and so on.
well i hope that shows you guys some of the basics
- HotNoob
- Reputation: 0
- Posts: 169
- Joined: Sun May 02, 2010 2:38 am
- Highscores: 0
- Arcade winning challenges: 0
|
|