How many "cases" are possible in a "switch"? [closed]

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; Do you limit the number of cases? Let's look at the examples:

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

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

Case 276384945
Informação.Text = "..."
    
asked by anonymous 30.07.2017 / 05:30

1 answer

10

How old do you think it will take you to write almost 300 million cases ? Have you noticed the impracticality of this? Even if there are only a few thousand, does it fit into the source code file that the compiler is able to process?

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

As the cat commented, if you have many, and by many you understand a few dozen or at most hundreds, you are doing something wrong. The compiler may know how to handle, and deals with thousands, but it does not make sense to do so. Most likely this code gets better computed using a loop or array (you have some questions that tell you about it in other languages here and here ).

Do not worry about it, case was not created to deal with this hypothetical situation, it becomes useless before the compiler squeaks.

    
30.07.2017 / 06:01