How many "cases" are possible in a "switch"?

Asked

Viewed 215 times

2

Case 1
Informação.Text = "Olá Mundo!"

Case 2
Informação.Text = "Tudo bem com você?"

Case 3
Informação.Text = "Que horas são?"

Notice that I added 3 (three) cases. Now a question; is there a limit to the number of cases? Let’s go to the examples:

Case 276384943
Informação.Text = "..."

Case 276384944
Informação.Text = "..."

Case 276384945
Informação.Text = "..."
  • What language?

  • Visual Basic - NET

  • And what exactly do you want to know?

  • Limit the amount of "cases" in the project?

  • 4

    I don’t know if there is a case limit, you can use as many as you want. Of course, if you have too many it is a sign that you need to refactor the code.

  • My concern is to suddenly reach the limit the numbers of "cases". Because I don’t know much about programming and the simplest way I’ve learned is the above example.

  • I suggest you start around here then, to better understand the functioning of the case.

  • This reply will also help in understanding the case.

  • The language limit is arbitrarily large, which corresponds to a maximum of an integer of 32 bits. Since it doesn’t make sense, because the maximum number of lines on file is 65,535 lines. But nobody passes it, after all.

  • @Marcosmeireles The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

Show 5 more comments

1 answer

11

How many years do you think it will take to write nearly 300 million cases? Do you realize the impracticality of this? Even if it’s only a few thousand, it fits in the source code file that the compiler is able to process?

Unless you have a pattern that allows you to put this in a loop, which already eliminates the case.

As the cat commented, if you have many, and by many understand a few tens or at most hundreds, you are doing something wrong. The compiler can handle it, and it handles thousands, but it doesn’t make sense to do that. Most likely this code looks better in computed form, using a loop or array (has some questions that speak of it in other languages here and here).

Don’t worry about it, the case was not created to deal with this hypothetical situation, it becomes useless before the compiler chiar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.