|
1 registered members (Quad),
4,945
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
New conditional statments
#248892
01/29/09 21:02
01/29/09 21:02
|
Joined: Jan 2008
Posts: 1,580
Blade280891
OP
Serious User
|
OP
Serious User
Joined: Jan 2008
Posts: 1,580
|
Is it possible to add things like php has for example
if(conditions) { do something }
can be
if(conditions) do something
and this
if(conditions) { var = do something } else if(conditions) { var do something }
could be
var = (conditions ? true : false);
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
Re: New conditional statments
[Re: Blade280891]
#248893
01/29/09 21:06
01/29/09 21:06
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
if(conditions) do something ^ you can use this, if there is only one statement after the if.(one ";" ) this is same in php. how would it supposed to understand what is condition dependant or not without {}'s when there are more than one statements/instructions.
(conditions ? true : false)-> yeah miss that from PHP, but i guess this is not necessary
3333333333
|
|
|
Re: New conditional statments
[Re: Quad]
#248894
01/29/09 21:09
01/29/09 21:09
|
Joined: Jan 2008
Posts: 1,580
Blade280891
OP
Serious User
|
OP
Serious User
Joined: Jan 2008
Posts: 1,580
|
Well in php you can do things like
if(condition) echo "true"; elseif(condition) echo "maybe"; else echo "true";
Last edited by Blade280891; 01/29/09 21:15.
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
Re: New conditional statments
[Re: Blade280891]
#248896
01/29/09 21:17
01/29/09 21:17
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
you can do it in lite-c too. as in your example, there is only 1 statemens(echo ...  after ifs end elses. edit: this will work:
<?php
$a = true;
$b = true;
if($a)
echo "a";
elseif($b)
echo "b";
else
echo "-";
?>
this will complain about elseif and which if it stands for:
<?php
$a = true;
$b = true;
if($a)
echo "a";
echo "2nd statement";
elseif($b)
echo "b";
else
echo "-";
?>
this will echo "2nd stamaent" but not "a"
<?php
$a = false;
if($a)
echo "a";
echo "2nd statement";
?>
for lite-c: this wont print "a" but will print "2nd statement", if you set a to 1, both will be printed.
var a =0;
void main(){
if(a)
printf("a");
printf("2nd statement");
}
Last edited by Quadraxas; 01/29/09 21:24.
3333333333
|
|
|
Re: New conditional statments
[Re: jcl]
#248969
01/30/09 14:33
01/30/09 14:33
|
Joined: Jan 2008
Posts: 1,580
Blade280891
OP
Serious User
|
OP
Serious User
Joined: Jan 2008
Posts: 1,580
|
Yeah quad i know that about php  , JCl what about the other one var = (condition ? true : false)
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
Re: New conditional statments
[Re: HeelX]
#249060
01/31/09 12:07
01/31/09 12:07
|
Joined: Jan 2008
Posts: 1,580
Blade280891
OP
Serious User
|
OP
Serious User
Joined: Jan 2008
Posts: 1,580
|
ok but it is called ternary not trinary  Also JCL, when you implement it will it be like the current php one or the new php one (php 6), the new php one is like so var = ($condition ?: true)//Does not requrie a false //where as the current one does More details here http://www.php.net/~derick/meeting-notes.html#ifsetor-as-replacement-for-foo-isset-foo-foo-something-else
Last edited by Blade280891; 01/31/09 12:08.
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
Re: New conditional statments
[Re: Blade280891]
#249064
01/31/09 12:23
01/31/09 12:23
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
that is unnecessary. i don't understand you all talking about php which is badly-designed and by far not as powerful as c++ o.O. for the examples in your code, how about: var = (bool)condition;
var = condition && true; and for the examples in your link simply use the ternary operator. i don't think shortening this one seems necessary. an alternative is below. var = condition ? foo : var;
condition && (var = foo); rather request c++ features, such as: while ( p = (file = open_file( (p && p->name) || foo ), file.seek(another), file.readline()) ) {}the ,-operator would often give you the possibility to write more compact code.
|
|
|
Re: New conditional statments
[Re: Joey]
#249068
01/31/09 12:27
01/31/09 12:27
|
Joined: Jan 2008
Posts: 1,580
Blade280891
OP
Serious User
|
OP
Serious User
Joined: Jan 2008
Posts: 1,580
|
PHP is only badly designed for those who can't use it Please do not try and spin this thread off into a poitnless discussion when the feature has been added onto the forcast page Edit: the true and false in my example was just to show where you would put the values, not has to be put so (bool) will not help if you want it to change the var to text or similar
Last edited by Blade280891; 01/31/09 12:32.
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
|