Forum Moderators: open
------------------
versus:
if (i am green)
{say "i am green"}
say "i might (not) be green"
------------------
if you try the first test as green the result is:
"i am green"
if you try the second test as green the result is:
"i am green"
"i might (not) be green"
[edited by: SarK0Y at 1:42 am (utc) on Dec. 8, 2008]
We generally do not use goto's that often in writing conditionals. An else statement is certainly cleaner, too. Stick with it and you'll be good. :)
The only time I can think that it is necessary to use a "goto" for a conditional, or in this case a "branch", would be in assembly language. And by the looks of your pseudocode you're far from coding that. ;)
$login = '<form..... (username, pass, submit . . . </form>';
We want to output an instructional message above the form. To avoid confusing the users, we want the message to be specific to the current state.
if ($error) { $msg = "An error has occurred: $error. Please try again."; }
else { $msg = "Please log in with your email address and password."; }
$total_output = $msg . $form;
So we want the form to output in either case, but the message varies based on the conditions.
Even a ternary/short circuit evaluation is an "else"
$msg = ($error)?$login_msg:$errmsg;
How would you do that without an else? Without an else, you get redundant messages - both the error and the log in instructions. People don't like to read. It may only take that one extra line of text for them to leave your site and tell everyone it's broken.
if ($error) { $msg = "An error has occurred: $error. Please try again."; }
$msg .= "Please log in with your email address and password.";
$total_output = $msg . $form;
Using else is one more tool by which you can obtain specificity in your code, use it if you need it. Eventually, you'll stumble on one.
[edited by: SarK0Y at 7:58 pm (utc) on Dec. 11, 2008]