Beginner PHP Tutorial – 27 – for Loop

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

34 responses to “Beginner PHP Tutorial – 27 – for Loop”

  1. Remove Kebab Avatar

    Why it $count = 1; will not assigned new variable?

  2. Franck Tassembedo Avatar

    for ($num=10 ; $num<=100; $num +=10){
    echo $num . '<br>';} in case u want to increment by mor than one (here by 10)

  3. Todd Matthews Avatar

    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

  4. Genia Avatar

    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?

  5. Mohsin Ali Avatar

    <?php
    /* while($counter<=10)
    {
    echo "Its ".$counter." Number<br>";
    //echo 'Now';
    $counter++;
    }
    */
    ?>

  6. Peter Baloi Avatar

    I was hoping after 27, you put in 28 to explain foreach loop

  7. Ali Sattar Avatar

    <?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 🙂

  8. Rob Hawkins Avatar

    what about the foreach loop? O_o

  9. Cj Vaans Avatar

    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.

  10. ted maglasang Avatar

    WHILE, DO and FOR is exactly the same in javascript.

  11. William Abboud Avatar

    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 🙂

  12. EpicAglet Avatar

    Funnily enough, once you really start programming you often use them more than any other kind of loop.

  13. Ђорђе Живановић Avatar

    Finally I understand while loop.

  14. omkarjere Avatar

    for loop for the win !!!

  15. Kaustubh Kishore Avatar

    as the video number is increasing the views are decreasing

  16. Zocress Avatar

    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.

  17. Mega Bidders Avatar

    The arabic video on the right with the guy with the moustache is really distracting lol, great tutorials though Alex! 😛

  18. darkshad109 Avatar

    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.

  19. HDDesign1337 Avatar

    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

  20. Lawrence R Avatar

    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.'
    '; } ?>

  21. billy bob Avatar

    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?

  22. slayer0273 Avatar

    not to confuse Java with javascript..

  23. mikez2 Avatar

    "i" is generally used as the count variable

  24. DeuceisLegit Avatar

    This is just like c++. I'm cruising through this 😀

  25. Biosystem Studios Avatar

    the for loop is my favorite of the loops. it's the most flexible

  26. H. David Levine Avatar

    Maybe it's been asked already. . . with PHP, why does a browser need to run javascript too?

  27. Hitarth Patel Avatar

    @ahmadu007 PHP and C++ and JAVA have similarities too.

  28. Ahmad Umair Avatar

    @Musichkp yeah! I, for one find the ones in javascript and PHP quite similar

  29. Hitarth Patel Avatar

    All the loops are the same in most of the languages.

  30. Mau Ferrusca Avatar

    clear, concise and easy to follow. thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *