if()

tittat

Active Member
Messages
2,478
Reaction score
1
Points
38
Sorry, but i didn't get you.....
Do you want any help regarding "if" statements.???

*****Thread Moved to Programming Help*****
 
Last edited:

ichwar

Community Advocate
Community Support
Messages
1,454
Reaction score
7
Points
0
vTurato, that's not totally true. the syntax is:

Code:
if([I]condition[/I])
{
[I]action[/I]
}
 
Last edited:

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
just to clarify if() has two possible syntax

if the action clause is in a single line:
PHP:
if(argument) action;
or
PHP:
if(argument) {action;}

or if it spans over multiple lines:
PHP:
if(argument){
  action1;
  action2;
}
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
ichwar, he is actually correct. If you've only got one line after the if statement, you don't need braces.

PHP:
if ($value == true)
  echo "Hi";
else
  echo "Bye";
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
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.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
syntax readability wise, it's better to use one line for everything when there is one command
PHP:
if(argument) action;
and braces when there is many commands
PHP:
if(argument){
  action1;
  action2;
}
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
syntax readability wise, it's better to use one line for everything when there is one command
PHP:
if(argument) action;
and braces when there is many commands
PHP:
if(argument){
  action1;
  action2;
}
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.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
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.
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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.


PHP:
if ($act == "main")
{
    echo "hi";
    if ($logged) echo "welcome";
    $a*5;
}
vs
PHP:
if ($act == "main")
{
    echo "hi";
    if ($logged)
        echo "welcome";

    $a*5;
}
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
yes, AND is && and OR is ||

@xPlozion:
Was about to right pretty much the same thing...
 
Last edited:
Top