If Statements, can you have multiple?

In this code can you have the two if else statements? and is there an easier way to approach this?

const int leftbutton = 4;
const int rightbutton = 2;
const int yellow = 13;
const int red = 12;
const int comp = 1;
const int comp2 = 2;
int x;
int buttonstate = 0;

void setup()
{
  pinMode(leftbutton, INPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(rightbutton, INPUT);
  
}
  
  // to read the button state do buttonState = digitalRead(buttonPin);
  //basically the state = digitalRead(pin of button output);
  //If button one(comp) is == to x, then light up the yellow light. 
  //else turn on the red led
  
  //digitalWrite(pin, LOW/HIGH)
  
void loop()
 {  // 1 is the right one
    x = random(1,2);
    //If the leftbutton is pressed and the number is rand num is 1, tu
    if(((buttonstate = digitalRead(leftbutton) == HIGH) && (x == comp)))
    {
   
      digitalWrite(yellow, HIGH);
      delay(1000);
      digitalWrite(yellow, LOW);
    }
    else
    {
    digitalWrite(red, HIGH);
    delay(1000);
    digitalWrite(red, LOW);
    }
    
    
    if(((buttonstate = digitalRead(rightbutton) == HIGH) && (x == comp)))
    {
      
      digitalWrite(yellow, HIGH);
      delay(1000);
      digitalWrite(yellow, LOW);
      
    }
    else
    {
    digitalWrite(red, HIGH);
    delay(1000);
    digitalWrite(red, LOW);
    }
     
      
 }

Yes, look at functions.

Mark

Have you tried the code? Does it work? Isn't that the easiest and quickest way to get an answer?

Personally I would place the "buttonstate = digitalRead(leftbutton)" before the if statement just for greater clarity. The if statement can then be shorter.

...R

    if(((buttonstate = digitalRead(rightbutton) == HIGH) && (x == comp)))

Doesn't do what you hope.

  int foo ;
  foo = 7 == 9 ;

Sets foo to 0, since assignment binds least tightly of all (as it should).

You meant

    if ((buttonstate = digitalRead(rightbutton)) == HIGH && x == comp)

Or, much more maintainable,

    boolean right = digitalRead (rightbutton) ;
    if (right && x == comp)

Using boolean avoids all the use of HIGH and LOW which clutters up the code,
and renaming the variable to indicate which button aids maintainability of the code.

Putting "state" into the name of a variable is unnecessary, all variables are stateful.

Compare the readability of the original code fragment with my version - less clutter,
more obvious.

Thanks to all