Programming - Nested Statements

Once upon a time, I was a newbie too. Blah blah blah introduction blah blah blah...

Someone asked me whether this code is possible.

From channel ##php at Freenode. $k = 4; if (!(isset($_SESSION['loggedin']))) { for ($i = 5; $i < 8; $i++): $j = $i; if ($j == 6) $k = 5; else $k = 4; }		else { for ($i = 5; $i < 10; $i++): $j = $i; if ($j == 6 || $j == 8) $k = 5; else $k = 4; }		?>">" src="<? sokg; getImage('info'); getPage($j); isSelected($j) ?>.png" alt="<? getTitle($j) ?>"/><? if (($i != 7) && (!(isset($_SESSION['loggedin'])))) getImage('space'); elseif ($i != 9) getImage('space'); endfor;

Explanation about grammar blah blah blah.

As an analogy, think of statements as brackets that must be closed properly. Thus, this is correct: ({[]})

If you "convert" it to PHP, it's like: if ($condition) { foreach ($my_array as $e) { if ($another_condition) { do { // do something... } while ($blah); }   } }

However, this is wrong: ([{]})

Or, in PHP: if ($condition) { foreach ($my_array as $e) { if ($another_condition) { }

// do something... } }

Theory, theory. Theories are meant to further confuse you. Therefore, I will further confuse you with confusing theory.

Compilers/interpreters put these brackets in a stack, on a first in first out basis.

To illustrate: ({[]}) 1. +---+ | ( | <-- push +---+ +---+ |  | +---+ +---+ |   | +---+ +---+ |   | +---+

2. +---+ | { | +---+ +---+ | ( | +---+ +---+ |  | +---+ +---+ |   | +---+

3. +---+ | [ | +---+ +---+ | { | +---+ +---+ | ( | +---+ +---+ |  | +---+

4. +---+ | ( | +---+ +---+ | [ | +---+ +---+ | { | +---+ +---+ | ( | +---+ 5. +---+ |  | <-- popped because of ) +---+ +---+ | [ | +---+ +---+ | { | +---+ +---+ | ( | +---+ 6. +---+ |  | +---+ +---+ |   | +---+ +---+ | { | +---+ +---+ | ( | +---+ 7. +---+ |   | +---+ +---+ |   | +---+ +---+ |   | +---+ +---+ | ( | +---+ 8. +---+ |   | +---+ +---+ |   | +---+ +---+ |   | +---+ +---+ |   | +---+