Closing nested statements

07-25-07, 11:09 PM
|
|
Wannabe Coder
|
|
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Closing nested statements
I have had several people help me with coding and I understand it a fair bit. However, I cannot seem to wrap my brain around the logic behind closing multiple statements. For example:
Which ones close D,E,F?
Any helpful lessons appreciated.
Andy
Last edited by Andy128; 07-25-07 at 11:13 PM.
|

07-26-07, 02:17 AM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
My advice: Write your code cleaner, and you won't need comments to know which bracket closes which statement.
Personally, I indent all code inside a statement by one, like this:
It's much easier to read and follow.
|

07-26-07, 08:31 AM
|
|
Wannabe Coder
|
|
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thaks Nico-
I appreciate the tip. How ever, the logic behind the closing is what escapes me. For instance. The "D" bracket is the very last one closed before the closing tag while "E" and "F" were closed directly following the table and before the closing of the file. Is there a rule to this that I am missing or simply the logic itself.
And by cleaner, I take it that you simply meant the indentations not the logic or syntax it self of the script presented.
Andy
|

07-26-07, 10:32 AM
|
 |
Code Guru
|
|
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Andy128
Thaks Nico-
I appreciate the tip. How ever, the logic behind the closing is what escapes me. For instance. The "D" bracket is the very last one closed before the closing tag while "E" and "F" were closed directly following the table and before the closing of the file. Is there a rule to this that I am missing or simply the logic itself.
|
This is because "bracket D" is your loop, and you need to have things happen in your loop. E and F happen in your loop and will need to be closed inside of D because you started them in D, understand?
Quote:
|
And by cleaner, I take it that you simply meant the indentations not the logic or syntax it self of the script presented.
|
I'm not going to comment on the logic, but the syntax could use some work, try making your code so a majority of it is run before any HTML is output to the web browser. This can be done in your case by putting all of that echoed html into 1 string var, then echoing that string 1 time. instead of calling echo X number of times.
__________________
"BTW, I can't program at all the only thing I figured out is how to upload templates to my server."
|

07-26-07, 12:33 PM
|
|
Wannabe Coder
|
|
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Nova-
Quote:
|
try making your code so a majority of it is run before any HTML is output to the web browser. This can be done in your case by putting all of that echoed html into 1 string var, then echoing that string 1 time. instead of calling echo X number of times.
|
If you have the time, could you provide a small snippet of example on this?
Thanks again-
Andy
|

07-26-07, 12:59 PM
|
 |
Code Guru
|
|
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
__________________
"BTW, I can't program at all the only thing I figured out is how to upload templates to my server."
|

07-26-07, 01:07 PM
|
|
Wannabe Coder
|
|
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Nova- I will sink my teeth into this straight away. Why is it that these cool examples are not covered in most books?
Any reference material you would suggest to pick up the tricks of the trade?
Andy
|

07-26-07, 02:02 PM
|
 |
Code Guru
|
|
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
__________________
"BTW, I can't program at all the only thing I figured out is how to upload templates to my server."
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|