so many if.. and Else if command

hii,

i’m very new to arduino and this is my 1st project, can some one help me to make this work smple…
i need to read several input in A0 pin and send data to shiftregister. code sample as below,

//void loop(){
Ival = analogRead (inputSen);
Lval = analogRead (inputLdr);
Sval = digitalRead (secuOn);

if (440 < Ival && Ival < 460 && Lval >300 && Sval== 1){

digitalWrite(latchPin, LOW);// start to send data
shiftOut(dataPin,clockPin,MSBFIRST,B11000000); // send this cormand
digitalWrite(latchPin, HIGH);// send the comand
}
else if(440 < Ival && Ival < 460 && Lval >300 && Sval== 0){

digitalWrite(latchPin, LOW);// start to send data
shiftOut(dataPin,clockPin,MSBFIRST,B01000000); // send this cormand
digitalWrite(latchPin, HIGH);// send the comand
}
else if (210 < Ival && Ival < 240){

digitalWrite(latchPin, LOW);// start to send data
shiftOut(dataPin,clockPin,MSBFIRST,B10100000); // send this cormand
digitalWrite(latchPin, HIGH);// send the comand
}

else if (500 < Ival && Ival < 530){

digitalWrite(latchPin, LOW);// start to send data
shiftOut(dataPin,clockPin,MSBFIRST,B11100000); // send this cormand
digitalWrite(latchPin, HIGH);// send the comand

so on,

i have more to write and please help me to make my life easier…

thank you

if (440 < Ival && Ival < 460 && Lval >300 && Sval== 1){
else if(440 < Ival && Ival < 460 && Lval >300 && Sval== 0){

Note that there are tests common to both of these so you could do

  if (440 < Ival && Ival < 460 && Lval > 300)
  {
    if (Sval == 1)
    {
      //do stuff
    }
    else
    {
      //do other stuff
    }
  }

It seems you should use a function.

void sendCommand(byte command)
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, command);
  digitalWrite(latchPin, HIGH);
}
  if (440 < Ival && Ival < 460 && Lval >300 && Sval== 1){

I have never been able to wrap my head around writing an if statement backwards like this. Please explain what this statement is saying, in English.

Compound if statements are rarely the right answer. Nested if statements are far simpler to make correct AND to make sure that every possible path is covered.

PaulS: Compound if statements are rarely the right answer. Nested if statements are far simpler to make correct AND to make sure that every possible path is covered.

+1

With compound statements you can never be sure which element was false and caused the test to fail. With 4 elements in a test there is 1 way to be successful and 15 ways to fail.

With nested statements there is no confusion.

...R