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
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 

Link to comment
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 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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.