Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6018313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:15:25+00:00 2026-05-23T03:15:25+00:00

I was wondering: is there a way to make Objective-C support a multi-variable switch

  • 0

I was wondering: is there a way to make Objective-C support a multi-variable switch construct?

I mean, very often I have to deal with problems in which the solution depends on a pair of variables instead of a single one. For a long list of single variable values one can use a simple switch/case construct:

switch (var) {
    case 0: ...
    case 1: ...
    default: ...
}

But when you have to deal with the combination of two values you often happen to do something like this:

switch (var1) {
    case 0: 
        switch (var2) {
            case 0: ...
            case 1: ...
        }
    case 1: 
        switch (var2) {
            case 0: ...
            case 1: ...
        }        
    ...
}

And it gets more and more complicated … What I’d really love to do is something like this:

switch (var1, var2) {
    case (0,0) : ...
    case (1,0) : ...
    case (*,1) : ...
    default: ...
}

that will result in a more simple and readable construct. Is there any solution to support such a structure? Or a slight variation of this one?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:15:26+00:00Added an answer on May 23, 2026 at 3:15 am

    I like the answer from saphrosit but I’ll make try to make it easy to understand.

    Imagine the possible outcomes of your problem as squares in a grid where one edge of the edge of the grid represents values of var1 and the other edge represents the possible values of var2, then if you incrementialy counted through the squares of the of the grid you would it get something like this

          ||                              var1                                   |    
          ||    0    |     1     |     2     | ... |     j     | ... |   n-1     |
    ======++=====================================================================|
        0 ||    0    |     1     |     2     | ... |     j     | ... |   n-1     |
       ---||---------+-----------+-----------+-----+-----------+-----+-----------|
        1 ||    n    |    n+1    |    n+2    | ... |    n+j    | ... |  n+(n-1)  |
       ---||---------+-----------+-----------+-----+-----------+-----+-----------| 
        2 ||   2*n   |   2*n+1   |  2*n+2    | ... |   2*n+j   | ... | 2*n+(n-1) |
     v ---||---------+-----------+-----------+-----+-----------+-----+-----------|
     a    ||    .    |     .     |     .     |     |     .     |     |  .        |
     r ---||---------+-----------+-----------+-----+-----------+-----+-----------|
     2  i ||   i*n   |   i*n+1   |   i*n+2   | ... |   i*n+j   | ... | i*n+(n-1) |
       ---||---------+-----------+-----------+-----+-----------+-----+-----------|
          ||    .    |      .    |      .    |     |     .     |     |  .        |
      ----||---------+-----------+-----------+-----+-----------+-----+-----------|
      m-1 || (m-1)*n | (m-1)*n+1 | (m-1)*n+2 | ... | (m-1)*n+j | ... |   mn-1    | <-- (m-1)*n+(n-1) = m*n-n + (n-1) = mn-1
    ------||---------+-----------+-----------+-----+-----------+-----+-----------|
    

    This would is called a row major matrix since you start by counting accross the rows. There is also a column major matrix where you start counting down first instead of across. This is how matrixes are stored in the C BLAS library so it should be very fimilar to many people.

    In your case the outcome you’re looking for can be addressed as var3 = var2*n + var1 you could lay this out in code as

    #define N 10 // Maximum size of var1
    
    int main() {
    
       int var1 = 1;
       int var2 = 1;
    
       switch(var1 + var2 * N){
          case 1 + 1 * N: printf("One One"); break;
          case 2 + 2 * N: printf("Two Two"); break;
          default:
          printf("Bada Bing");
       }
    
       return 0;
    }
    

    NOTE: the code that was here earlier wouldn’t have worked, this works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

wondering if there's any way to make it so that a list I have
I am wondering if there is a way to make ASP.NET controls play nicely
I've been wondering if there's a way to parse XML in Objective C as
I was wondering if there is a way to make a UIImagePickerController use a
I was wondering if there is a way to make an easy keyboard shortcut
I was wondering if there was any way to make the scope of a
I have a quick JavaScript question. I was wondering if there's a way to
I'm wondering if there's any way to populate a dictionary such that you have
I was wondering if there was a way that I can declare a variable
I was wondering if there is way to open another page using a Modal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.