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 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    Newport Beach, California
    Posts
    96
    Thanks
    11
    Thanked 1 Time in 1 Post

    if with or + continue: Newbie question

    hi.

    learning PHP.

    this code works fine:

    PHP Code:
    for ($count = -3$count <= 10$count++) {
        if (
    $count == 5) {
        continue;
        }                    
        echo 
    $count ", ";
        } 
    As expected, this outputs:
    -3, -2, -1, 0, 1, 2, 3, 4, 6, 7, 8, 9, 10,
    So how come I get nothing (no error, but no output) if I use 'or', like so:

    PHP Code:
    for ($count = -3$count <= 10$count++) {
        if (
    $count == || 6) {
        continue;
        }                    
        echo 
    $count ", ";
        } 
    I would expect it to output -3 to 10, skipping 5 and 6.
    Last edited by PonchoX; 03-22-2010 at 05:25 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    To get the desired output, you need to use
    PHP Code:
    if ($count == ||$count== 6) {
        continue;
        } 
    Your code
    PHP Code:
    if ($count == || 6) {
        continue;
        } 
    is equivalent to
    PHP Code:
    if ($count == || true) {
        continue;
        } 
    , which will evaluate to true, irrespective of the value of $count.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Apr 2009
    Location
    Newport Beach, California
    Posts
    96
    Thanks
    11
    Thanked 1 Time in 1 Post
    Thank-you, kindly.


  •  

    Posting Permissions

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