[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Beginner PHP Tutorial – 27 – for Loop
by
Tags:
Comments
34 responses to “Beginner PHP Tutorial – 27 – for Loop”
-
Why it $count = 1; will not assigned new variable?
-
for ($num=10 ; $num<=100; $num +=10){
echo $num . '<br>';} in case u want to increment by mor than one (here by 10) -
use '$i' instead of '$count'. and '$j' for nested loops… It is common practice in most other languages, and would make your code easier to understand by programmers who use other languages
-
I reproduce the code you write and wonder why the for loop gets me an error with the following code:
<?php
$counter = 1;
$counter2 = 1;while ($counter <= 10) {
echo $counter.'</br>';
$counter++;
}//Another way to do loops with do while
do {
echo 'True till 10 </br>';
$counter2++;
} while ($counter2 <=10)// For some reason, the for loop alone runs ok but with the 2 previous loops, the browser says there is a missing semi colon on line 18…
for ($x = 0; $x < 10; $x++) {
echo $x.'</br>';
}
?>Any idea Anyone?
-
<?php
/* while($counter<=10)
{
echo "Its ".$counter." Number<br>";
//echo 'Now';
$counter++;
}
*/
?> -
I was hoping after 27, you put in 28 to explain foreach loop
-
<?php
$number1 = 5;
$sum = 0;for ($i=1 ; $i<=10 ; $i++) {
$sum = $sum + $number1;
}echo 'The Summation is'. ' '. $sum;
?>
Here the output will be as follow:
The Summation is 50
Regards 🙂
-
what about the foreach loop? O_o
-
This is a bit confusing at first, but now this looks better than the while and do while loop. And it really is more organize.
-
Cool!
-
WHILE, DO and FOR is exactly the same in javascript.
-
Just a small note inside the curly brackets you don't need to write a variable with so many characters like $counter;$i would also do the trick for example because we are only using that particular variable inside the loop it is kind of equivalent to the:for (i=0;i<=10;i++){} in javascript for any of you front-end developers 🙂
-
Funnily enough, once you really start programming you often use them more than any other kind of loop.
-
Finally I understand while loop.
-
for loop for the win !!!
-
as the video number is increasing the views are decreasing
-
Hey, Alex.
I love your tutorial, but I found a thing that I do not think is true.
You tell in this tutorial, that a for-loop works the same way as a while-loop. I do not think, this is true. The differents would be, that a for-loop only checks for the statements once the loop is done, so it's checking the statements each time it runs. A while-loop, checks after all ; in the code. And once it is about to rerun. So for runs faster, than a while-loop. -
The arabic video on the right with the guy with the moustache is really distracting lol, great tutorials though Alex! 😛
-
With basic examples like the one being shown in the video it's hard to recognise the differences between the loops.
If say I was waiting on a boolean to switch to false i'd use the while and within that while run any code that will perhaps change the boolean.
If I only wanted to check that boolean 10 times rather than until it changes then the for loop is what I'd use.
The Do While is a bit of a niché function that will be rarely used but does have it's places.
-
`.O
-
Looks like you miss typed something. I tried pasting my code for you, but YouTube won't let me. Try just typing it out again, if not PM me
-
can anyone explain why this is echoed in my browser when i do exactly what is on screen as of 3:07 ?
this is what i get
=1 ; $count–) { echo $count.'
'; } ?> -
if you're reading this please answer,
so using all these loops is basically the same thing, just different ways? This "for loop" does the same as the "do while loop", just more efficiently?
-
not to confuse Java with javascript..
-
"i" is generally used as the count variable
-
This is just like c++. I'm cruising through this 😀
-
the for loop is my favorite of the loops. it's the most flexible
-
Maybe it's been asked already. . . with PHP, why does a browser need to run javascript too?
-
@ahmadu007 PHP and C++ and JAVA have similarities too.
-
@Musichkp yeah! I, for one find the ones in javascript and PHP quite similar
-
All the loops are the same in most of the languages.
-
greatt
-
clear, concise and easy to follow. thank you.
-
Thanks.
Leave a Reply