Oh, you're talking about the first one, yes, of course it does that.
Php sees the if condition, and parses if, if it's false, it'll completely skip whats in the brackets, and move to the else section. PHP doesn't care WHAT is between the brackets, it'll only parse the PHP code, as that's what it does.
You can go in and out of PHP as much as you want. Although echo may have been sufficient for this example, switching to html output and then switching back to echo out simple variables can be easier to manage with very large pages. Plus editors will colour code the HTML if it's outside of PHP, whereas inside the quote's it's all one colour, which can lead to some confusion.