A better way to do this pattern? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: A better way to do this pattern? (
/showthread.php?tid=642359)
A better way to do this pattern? -
Rotzank - 29.09.2017
So I'm doing this
PHP Code:
for(new i = 0; i < 10; i++)
{
printf("%i", i - (((i - 5) * 2) * (i / 5)));
}
// output
[00:49:20] 0
[00:49:20] 1
[00:49:20] 2
[00:49:20] 3
[00:49:20] 4
[00:49:20] 5
[00:49:20] 4
[00:49:20] 3
[00:49:20] 2
[00:49:20] 1
I just wanna know if there's a better way to do that.
Re: A better way to do this pattern? -
Misiur - 29.09.2017
You are worrying too much too early. Unless you notice that it's a bottleneck, I would not worry about it. However if you want more readable code, I'd go with
pawn Code:
new
total = 10,
peak = total / 2
;
for(new i = 0; i < total; i++)
{
new j = i;
if (i >= peak) {
j = total - i;
}
printf("%i", j);
}