Question: Can we use a condition to include cases in a switch statement?

My code:

```cpp
switch(menu_option)
{
  if (g_logged_in)
  {
     case 'L':
       cout << "Login Menu\n";
       break;
     case 'S':
       cout << "Signup Menu\n";
       break;
  }
  case 'A':
    foo();
    break;
  case 'B':
    bar();
    break;

  default:
    cout << "Invalid Option!\n";
}

```

When I compile the file, I get an error

```sh
[pewpew@Sierra cpp-something]$ c++ src/main.cc -o main.out
src/main.cc: In function 'int main()':
src/main.cc:53:13: warning: statement will never be executed [-Wswitch-unreachable]
   53 |             if (g_logged_in)
      |             ^~

```

Is it not at all possible?

Answer: 
there is no "case" above your code.
You can't do this. The case is most likely compiled into a CPU instruction, that only works on integers.
You must use the case and do the if() twice for both cases.
You cannot specify `case` statements conditionally. You would have to do something more like this:

```cpp
switch (menu_option)
{
  case 'L':
    // in C++17 and later, you can uncomment the following
    // attribute to avoid a compiler warning...
    //
    // [[fallthrough]];
  case 'S':
    if (g_logged_in)
    {
      if (menu_option == 'L')
        cout << "Login Menu\n";
      else
        cout << "Signup Menu\n";
    }
    else
      cout << "Invalid Option!\n";
    break;

  case 'A':
    foo();
    break;

  case 'B':
    bar();
    break;

  default:
    cout << "Invalid Option!\n";
    break;
}

```

Or this:

```cpp
switch (menu_option)
{
  case 'A':
    foo();
    break;

  case 'B':
    bar();
    break;

  default:
    if (g_logged_in)
    {
      if (menu_option == 'L')
      {
        cout << "Login Menu\n";
        break;
      }
      if (menu_option == 'S')
      {
        cout << "Signup Menu\n";
        break;
      }
    }
    cout << "Invalid Option!\n";
    break;
}

```