You only use braces if it's more than one line in an if statement
You only use braces if it's more than one line in an if statement
Sorry, but i didn't get you.....
Do you want any help regarding "if" statements.???
*****Thread Moved to Programming Help*****
Last edited by tittat; 02-19-2009 at 07:12 AM.
vTurato, that's not totally true. the syntax is:
Code:if(condition) { action }
Last edited by ichwar; 02-19-2009 at 01:38 PM.
just to clarify if() has two possible syntax
if the action clause is in a single line:
orPHP Code:if(argument) action;
or if it spans over multiple lines:PHP Code:if(argument) {action;}
PHP Code:if(argument){
action1;
action2;
}
ichwar, he is actually correct. If you've only got one line after the if statement, you don't need braces.
PHP Code:if ($value == true)
echo "Hi";
else
echo "Bye";
Just to add to diablo's points (which are correct)..
"One line" should read "one command", followed by a semi colon;
i.e. echo "something";
This can be done either on the same program line or with a return.
syntax readability wise, it's better to use one line for everything when there is one commandand braces when there is many commandsPHP Code:if(argument) action;
PHP Code:if(argument){
action1;
action2;
}
█ Xavier L | Community Public Relations Manager (Free Hosting Support)
█ Yes, my position is too cool to even exist!
█ How am I helping? Rate this post by clicking theicon below! (this is even better than "liking" a post)
█ Terms of Service | Acceptable Use Policy | x10Hosting Wiki
I disagree.
I think it is better to put the execution statement on a separated line to the condition statement. Indented, of course. That way, it becomes far more clearer to distinguish the condition and statement, and to match them up.
But of course, everyone works in a different way, and when it comes down to a difference in [parser ignored] whitespace, the final effect will be no different.
If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:
Not to contradict you, but when you work on projects with dozen of 1000 lines pages, you prefer the one line statements, although to indent everything might seem nicer.
█ Xavier L | Community Public Relations Manager (Free Hosting Support)
█ Yes, my position is too cool to even exist!
█ How am I helping? Rate this post by clicking theicon below! (this is even better than "liking" a post)
█ Terms of Service | Acceptable Use Policy | x10Hosting Wiki
Stop arguing, because it's an opinion. My preference is the same as Schoochi, but it's just a preference.
I've got some scripts that are over 1000 lines and i think it's easier to distinguish conditionals, because it's a new tab and not the same line.
vsPHP Code:if ($act == "main")
{
echo "hi";
if ($logged) echo "welcome";
$a*5;
}
PHP Code:if ($act == "main")
{
echo "hi";
if ($logged)
echo "welcome";
$a*5;
}