# A better way to do things.. ?

I have the following code snippet:
"      if ((Indeks == 1) || (Indeks == 4) || (Indeks == 7) || (Indeks == 10) || (Indeks == 13) || (Indeks == 16) || (Indeks == 19) || (Indeks == 22) || (Indeks == 25) || (Indeks == 28) || (Indeks == 31) || (Indeks == 34) ) "

Is there another way to express this, i.e. by checking if the value of Indeks contains one of the following values (1,4,7,10,13,16,19,22,25,28,31,34).

Something like
if (Indeks) is a member of [1,4,7,10,13,16,19,22,25,28,31,34) -> go further..

Anyone ?
###### Who is Participating?

Senior Software Engineer (Avast)Commented:
Efficient in terms of runtime performance but verbose

``````switch(Indeks)
{
case 1: case 4: case 7: case 10: case 13: case 16:
case 19: case 22 case 25: case 28: case 31: case 34:
// do something
break;
}
``````

Less efficient in terms of runtime performance but more compact.
http://www.cplusplus.com/reference/algorithm/find/

``````int i = {1,4,7,10,13,16,19,22,25,28,31,34};
size_t x = sizeof(i)/sizeof(i[0]);
if(i+x != std::find(i, i+x, Indeks))
{
// do something
}
``````
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.