Jump to content

[SOLVED] Conditional structures


odisey

Recommended Posts

Hello,

             I am wondering about conditional structures and the depth of nesting allowed, if at all.  For example I know I can do this:

 

 

If ()

       {

           if () 

 

                    {  Do this  }

 

                     else

 

                     { Do this  }

 

       }

 

   else

 

       {

 

             Do this

 

       }

 

}                  Is this OK to do?  If yes, how deep can one go ?

 

 

Marc

Link to comment
https://forums.phpfreaks.com/topic/79152-solved-conditional-structures/
Share on other sites

I am reading David Power's PHP Solutions and I am absolutely sure he stated "You can use as many if else statements as you like, just don't nest them.  I am looking for the page to re-read it as I though this is the problem I am having with a block of code.  So...other nested blocks I have, and example I have are nested...I am not sure why he said that..maybe I misread.  I am looking for it again...   

 

 

Marc 

I am reading David Power's PHP Solutions and I am absolutely sure he stated "You can use as many if else statements as you like, just don't nest them.  I am looking for the page to re-read it as I thought this is the problem I am having with a block of code.  So...other nested blocks I have, and example I have are nested...I am no sure why he said that..maybe I misread.  I am looking for it again...   

 

 

Marc 

 

 

PLEASE DELETE DOUBLE POST

like i said you can use it if you really needs it but nested ifs is very hard to maintain and very hard to read

so avoid it if you can avoid them but if the situation ask for it then theres no way for you to avoid it..

 

 

maybe instead of having tons of ifs inside your ifs you can replace them with switch for better readability of your codes

like i said you can use it if you really needs it but nested ifs is very hard to maintain and very hard to read

so avoid it if you can avoid them but if the situation ask for it then theres no way for you to avoid it..

 

 

maybe instead of having tons of ifs inside your ifs you can replace them with switch for better readability of your codes

 

I'm considering this.   I already coded a page of 45 questions with multiple checks, etc...  it is 7000 lines of code.  I need to add one more check to the lot...I got it installed and it works.  I just lost functionality of the inner most if statement.  I will re-evaluate the structure again .. looks like it should execute. 

 

I found the Power's statement.  Actually he said you can embed as many blocks of PHP into xhtml as you like ...  just don't nest them.  I mis-remembered-intrepreted-read what I read. 

 

OK  - Thank you for the feedback

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.