any easy way to code this if function?

ok we i just wanted to know if there was any easier way to code this

if ((t.dow==timerSetSu1) || (t.dow==timerSetMo1) || (t.dow==timerSetTu1) || (t.dow==timerSetWe1) || (t.dow==timerSetTh1) || (t.dow==timerSetFr1) || (t.dow==timerSetSa1))
        {
CODE HERE
}

Is there any other way to code the if statement to make it more clean?

something like :

if (t.dow==timerSetSu1 || timerSetMo1 || timerSetTu1 || timerSetWe1 || timerSetTh1 || timerSetFr1 || timerSetSa1
{
}

this way i dont have to keep repeating the "t.dow==" statement... please let me know as this is all new to me...

It may be simpler to exclude the things it isn't equal to.

if (t.dow==timerSetSu1 || timerSetMo1 || timerSetTu1 || timerSetWe1 || timerSetTh1 || timerSetFr1 || timerSetSa1

That won't work.

My gut feeling says there is another way ( perhaps quite different to your approach) but I don't know what question you are trying to answer. Can you describe that in plain language (i.e. without any code).

...R

i wanted to know if there is another way to combin them all into the if statement, i know the bottom code doesnt work, it was just an example of what i wanted it to do....

the top code is the same as the bottom but uses the "t.dow==" for each byte and i wanted to do something that doesnt have to repeat it self 7 times, hope that makes sense

switch (t.dow)
  {
  case timerSetSu1:
  case timerSetMo1:
  case timerSetTu1:
  case timerSetWe1:
  case timerSetTh1:
  case timerSetFr1:
  case timerSetSa1:
 
    // do something
    
    break;
  
    
  }

And if that doesn't work, a visit to http://snippets-r-us.com/ might help.

bryanmc1988:
i wanted to know if there is another way to combin them all into the if statement,

I know that's how you want to improve the code. But it does not tell me what the code is intended for.

I would like to see a description in this style "check if ABC and do XYZ" - a plain language description of the effect that the code will have when it works. The sort of description that would make sense to your Mum.

...R

Having timerSetSu, timerSetMo, etc.. is mad. Make them into an array.

Something like this

  daytimer[7]={whatever, whatever, whatever, etc..};
  
  for(n=0;n<7;n++)
    if(t.dow==daytimer[n])
      {//do your thing here
        
      }

//But it would be better still to know what day it is,  Then you could simply do
    if(t.dow==daytimer[TODAY])
      doYourThing();
if(t.dow==daytimer[TODAY])

Now that looks very sensible - if it is what the OP is trying to do.

I have asked him, but so far he has not told us.

(Something a mother could understand)

...R

Robin2:
I have asked him, but so far he has not told us.
(Something a mother could understand)

He'll learn to listen when his alarm clock refuses to let him have a lie in at the weekend :wink:

Is there any other way to code the if statement to make it more clean?

No. The C language does not provide a way to abbreviate that statement.
If you want to test if a equals b, c or d, (where a,b,c and d are variables) you have to write each test for equality explicitly:

 if(a == b || a == c || a == d) {...}

This doesn't work:

if(a == b || c || d) {...}

because it means "if a equals b OR c is non-zero OR d is non-zero"
and this also won't work:

if(a == b, c, d) {...}

Although this evaluates 'a==b' (unless the compiler optimizes it out), it does not use it. This statement is the same as if(d) - look up the comma operator.

If you have such a long if statement, chances are there's a better way to code the whole problem as KenF alludes to in #8.

Pete