Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: while ==

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    96
    Thanks
    2
    Thanked 0 Times in 0 Posts

    while ==

    Hello, why in a while cicle I can't use the equal operator? This code for example doesn't work

    PHP Code:
    <?php
    $i 
    0;
    do {
        echo 
    $i;
        
    $i++;
    } while (
    $i == 10);
    ?>
    but if I use <= it works

    PHP Code:
    <?php
    $i 
    0;
    do {
        echo 
    $i;
        
    $i++;
    } while (
    $i <= 10);
    ?>
    Thank you!

  • #2
    New Coder
    Join Date
    Apr 2012
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post
    Think about it, i starts at 0 but ONLY goes up by 1 if that code is run, but that code only runs while i is 10, but it will never be 10 because that code is never run.......... Think about it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •