U
U
Urukhayy2015-07-15 10:29:29
Programming
Urukhayy, 2015-07-15 10:29:29

How best?

1 option:

switch(a)
{
   case 0: 
   {
      b = 2;
      return 1;
   }
case 1: 
   {
      b = -1232;
      return 1;
   }
case 2: 
   {
      b = 12322;
      return 1;
   }
}

Option 2:
switch(a)
{
   case 0: 
   {
      b = 2;
   }
case 1: 
   {
      b = -1232;
   }
case 2: 
   {
      b = 12322;
   }
}

That is, if one of the cases is executed, the others will not work, and the second option is better?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman Kitaev, 2015-07-15
@Urukhayy

break

N
Noobkesan, 2015-07-15
@Noobkesan

firstly, in the second option, a break is needed, and secondly, this is not an optimization that you should worry about, but rather a matter of taste.

S
Sergey, 2015-07-15
Protko @Fesor

It is better to store the data in a map and issue it by key.

A
AI Lab, 2015-07-15
@vpuhoff

in general, it’s break, but in fact it doesn’t matter, if you are not going to check this case three billion times per second, any computer will gobble up this condition and will not choke even with hundreds of thousands of cycles per second.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question