If with else inside Else if..

hi, i'd like to know if its possible to do something like this:

if  (xxx xxxx) 

{

xxx;

} 

else if (zzzz zzzz)

{

if ( dddd dddd) {

dddd dddd;

}

else (ffff ffff) {

ffff ffff;

}}

else if etc etc etc

what i'm trying to do is to have an if and else insede an else if, but then be able to continue with more else ifs....

if there is a possible thing do what i want..could anyone give an example??? ( more understandable than mine jaja..)

Yes
However, there may be a better way to do what you are trying. A switch/case may be clearer (or not). A concrete example of your problem may help.

It’s really easy to test out your hypothesis.

Suggest you examine Switch/Case.

Could you give me an example of both possibilities? Else if with the if and else..and the switch case?

Keep this handy:

Switch/Case

else if

You can nest if/else statements like that. Just mind your {}s and it works fine.

Ok thanks for the info..so i can use an if and else inside an else if and goes on with else if to the last else to close the statement ?

If there is no need for it, you don't need to use an ending 'else'.

  if (x < 25)
  {
    //do something
  }
  else if (x == 25)
  {
    //do something
  }
  else if (x > 25)
  {
    //do something
  }
  else
  {
    //do nothing here
  }

thanks for the example, but i meant this:

 if (x < 25)
  {
    //do something

  }

  else if (x == 25)

  {

if (x = 25)  {          


    //do something

  }

else {

do another thing

}}


  else if (x > 25)

  {

    //do something

  }

  else

  {
    //do nothing here

  }

is it possible to do this?

if (x = 25) Yes, it is possible to assign 25 to x, and unconditionally execute some code.

(Hopefully you can see why we indent code)

ok AWOL thanks for the answer...i got it now..

else (ffff ffff) {

ffff ffff;

}

else is NOT followed by parentheses.

Don't do this either:

}}

If you run the auto-format function in the Arduino IDE it will split these apart onto separate lines like they should be.

Hi PaulS MorganS, let's see if i get it:

if  (xxx xxxx) 

{

xxx;

} 

else if (zzzz zzzz)

{

if ( dddd dddd) {

dddd dddd;

}

else {              HERE LIKE THIS...NO PARENTHESES

ffff ffff;

}                     AND THIS PART LIKE THIS?
}                     

else if etc etc etc

This

}
}

like this }} should never, ever happen.

ok thanks AWOL...

The auto-format tool is very good. If it appears to scramble your code then the code was wrong, not the tool.

thanks you MorganS, i'm playing with it right now...thanks for the tip..