odisey Posted November 27, 2007 Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 27, 2007 Share Posted November 27, 2007 Yes, you can and should do it. And you can go as deep as you like. Though it might get a bit messy after a while. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 27, 2007 Share Posted November 27, 2007 it all deepens on the situations if you need it use it if you can avoid it or minimize it, much better.. Quote Link to comment Share on other sites More sharing options...
odisey Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
odisey Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 27, 2007 Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
odisey Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.