Results 1 to 8 of 8

Thread: [RESOLVED] switch statement confusion

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Resolved [RESOLVED] switch statement confusion

    uuh I dunno how to do this but I sure do hope it's possible in C#

    I have a switch and I want code execution to fall from one case to another if a certain condition isn't met

    Code:
    switch (something)
    {
        case 1:
             if (val==true)
             {
                 //do stuff;
                 break;
             }
             else
              {
                   // go on to other case statements.... but how? it won't compile without break;
              }
        case 2:
        case 3:
    
    }
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: switch statement confusion

    From the VS help topic entitled "switch":
    Unlike the C++ switch statement, C# does not support an explicit fall through from one case label to another. If you want, you can use goto a switch-case, or goto default.
    You can fall through from one case to another only if the first case is empty.

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: switch statement confusion

    ah that sucks
    arg I don't think I should use goto
    thanks for the reply
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: switch statement confusion

    I don't get it.

    If you don't use break, your code will just carry one excecuting right?

    Surely one can use that logic to go to the next switch if a condition is not met?
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: switch statement confusion

    Quote Originally Posted by StrangerInBeijing
    I don't get it.

    If you don't use break, your code will just carry one excecuting right?

    Surely one can use that logic to go to the next switch if a condition is not met?
    if you put some code in a case block, and don't use "break" you will get a compile error. It would be nice if you could do it like in C++ though
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: switch statement confusion

    You'll have to resort to if statements, evaluating both conditions...

  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: switch statement confusion

    Quote Originally Posted by mendhak
    You'll have to resort to if statements, evaluating both conditions...
    REALLY?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: switch statement confusion

    Quote Originally Posted by MrPolite
    REALLY?
    Khafesho... aqa-e-mashang

Posting Permissions

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



Click Here to Expand Forum to Full Width