You might find this equivalent version closer to your initial train of thought:
Code:
if (!(i == 5 || i == 7 || i == 9))
Sometimes, though not likely in either of your examples, it may make sense to do a bit of arithmetic:
Code:
if (!(i >= 5 && i <= 9 && i % 2 != 0))
Then, if you find yourself checking the same integer variable repeatedly in an if-else chain, e.g.,
Code:
if (i == 0 || i == 1)
{
/* #1 */
}
else if (i == 2 || i == 3 || i == 5)
{
/* #2 */
}
else if (i == 4 || i == 6 || i == 7)
{
/* #3 */
}
else
{
/ * #4 */
}
It may make sense to convert it to a switch, e.g.,
Code:
switch (i)
{
case 0:
case 1:
/* #1 */
break;
case 2:
case 3:
case 5:
/* #2 */
break;
case 4:
case 6:
case 7:
/* #3 */
break;
default:
/* #4 */
}