Better range based IFs -
fml - 25.03.2013
Did you know that instead of this:
Код:
for(new i = 0; i < 50; i++) {
if(i >= 15 && i <= 30) {
print("ugly :(");
}
}
You can do this:
Код:
for(new i = 0; i < 50; i++) {
if(15 <= i <= 30) {
print("yay!");
}
}
Which is much more compact and clear?
Re: Better range based IFs -
kamzaf - 25.03.2013
personally number 1 for me is more clear to me, it makes more sense. Like loop through all players, if within the loop i is in betweem 15 and 30 it will print ugly. Correct me if im wrong.
Re: Better range based IFs -
park4bmx - 25.03.2013
they both do the same things, but in situations like this i would go with the 2nd one
Re: Better range based IFs -
fml - 25.03.2013
Quote:
Originally Posted by kamzaf
personally number 1 for me is more clear to me, it makes more sense. Like loop through all players, if within the loop i is in betweem 15 and 30 it will print ugly. Correct me if im wrong.
|
For you, if(i >= 15 && i <= 30) is more clear than if(15 <= i <= 30) ? o.O They both do the same..
Re: Better range based IFs -
park4bmx - 25.03.2013
something didn't look good to me
Hmm.
1st one
meaning
if
20 is the
same/bigger then
15
AND
if
20 is the
same/lower then 30
2nd way
meaning:
if
20 is
same/smaller then
15
AND
if
20 is
same/samller then
30
NOT the same
Re: Better range based IFs -
Finn - 25.03.2013
I don't know if that's just an example, but I don't understand why you have so much bigger loop than what you actually need.
Код:
for(new i = 15; i <= 30; i++)
{
print("yay!");
}
Re: Better range based IFs -
fml - 25.03.2013
Quote:
Originally Posted by park4bmx
something didn't look good to me
Hmm.
1st one
meaning
if 20 is the same/bigger then 15
AND
if 20 is the same/lower then 30
2nd way
meaning:
if 20 is same/smaller then 15
AND
if 20 is same/samller then 30
NOT the same
|
They ARE the same.
if(15 <= i <= 30)
- i is same / bigger than 15
- i is less / same than 30
@Finn - It is only an example.
Re: Better range based IFs -
park4bmx - 25.03.2013
a 2nd look yes,
i too the "<=" as a point of the
i on its right side
but then again 15 does the check not
i
Re: Better range based IFs -
Misiur - 25.03.2013
Well, if you are interested, then learn about Yoda conditionals (I learned it from symfony coding standards).
Instead
you do
Why? Sometimes people make typos. And we are people. So if there was
Then you'd get random assignemnt istead of comparison
Syntax error, assigning variable to constant.
Note:
In PAWN we have "warning 211: possibly unintended assignment;", but still this is useful if you operate with a number of languages
Re: Better range based IFs -
fml - 25.03.2013
Quote:
Originally Posted by Misiur
Well, if you are interested, then learn about Yoda conditionals (I learned it from symfony coding standards).
Instead
you do
Why? Sometimes people make typos. And we are people. So if there was
Then you'd get random assignemnt istead of comparison
Syntax error, assigning variable to constant.
Note:
In PAWN we have "warning 211: possibly unintended assignment;", but still this is useful if you operate with a number of languages
|
I know about them, but I never made such a mistake and it really just makes less sense imo.