Digital HIGH, LOW Question

I'm using a zero cross detector to determine when a signal is positive and negative. That part of the circuit works fine but in another section I need to control a relay based on the signal without using delay(). I want to set the relay LOW when the zero cross is HIGH and the relay HIGH when the zero cross is LOW. I need to keep the code efficient so is there a way I can set the relay state opposite to the zero cross state without using if statements.

int crosspin=2;
int crosstime;
int prestate=0;
int state;
int pretime=0;
int peakpin=A8;
int relay=8;
int peak;
int ctr=0;

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly: 
  Serial.print("peak= ");
    Serial.print("time= ");
    Serial.print("time= ");


Thanks for any help.

It would be best to use a boolean for state (or another variable if state can be other than 0 or 1..

bool state;

// do stuff to set state

You use - for numbers, to invert a boolean you use ! (logical not)

  digitalWrite (relay, !digitalRead (crosspin)) ;

no need for any variables if you aren't holding on to state.