CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    what happens when case has no content

    what happens in the following case


    Code:
    switch(somechar)
    {
        ...
        ....
        case '=' : 
       case 'D' ://do something
                break;
     }

    will case 'D" also be entered when the character is "=" ??

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: what happens when case has no content

    Yes.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: what happens when case has no content

    It enters the next case because there is no "break" at the end of it, not because it has no content.
    Code:
    switch ( x )
    {
       case 1:
          func1();
       case 2:
          func2();
    };
    if x is 1 it will do func1() and func2(), if x is 2 it will do only func2().

  4. #4
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    Re: what happens when case has no content

    thanks folks.

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

Featured