C++ questions

I want to run a code according to value of an integer

I don’t know why it’s not working correctly

If(i = 1,3,5,7)
{
Code 1 ;
}
If(i = 2,4,6)
{
Code 2 ;
}

Or i have to use or Boolean here in the if

Like i = 1 || i = 3 || i = 5 || i =7
This doesn’t feel good to do

In this specific case you can use modulo to check if it’s odd (i % 2 == 0 checks whether i is even). Remember = sets while == checks equivalence.

In more general terms, you can use arrays.
image

3 Likes