Help optimize this code
#1

if(strlen(inputtext) <6 || strlen(inputtext) >24)

Someone can optimize this code?
Reply
#2

That's checking the length of a string, thus unless your using at for something "special"... that is the most efficient way.
Reply
#3

What do you mean optimize? btw try
pawn Код:
if (6 < strlen(inputtext) < 24)
Reply
#4

Quote:
Originally Posted by Cannary2048
Посмотреть сообщение
What do you mean optimize? btw try
pawn Код:
if (6 < strlen(inputtext) < 24)
That's i need, sorry for my bad english thanks!
Reply
#5

Quote:
Originally Posted by Cannary2048
Посмотреть сообщение
What do you mean optimize? btw try
pawn Код:
if (6 < strlen(inputtext) < 24)
That wouldn't work... and IF statement is like a real life scenario?

Example: I have more "dodo"'s than you.

pawn Код:
if(IceCubeDodoCount > CannaryDodoCount)
You can't if a 3 statements like that as it's not an if your saying:

if 6 is more than string text is more than 24. What would that even return: Example

pawn Код:
if(IceCubeDodoCount > CannaryDodoCount < OtherDudeDodoCount)
Now there are 3 statements 2 checks, however... there no way you can if that statement.

Even if it did work you last operator would have to be '>' not '<' to prevent it exceeding it's return. The original code posted, is the most optimised way. However you shouldn't concentrate too much on cosmetic looks of coding or small optimisations like this. Modern compilers are likely going to poop out the same code anyway, concentrate more on code readability unless you code runs slowly.

As you progress in your journey of learning Pawn, your coding style naturally becomes better anyway. Remember, always compare an if to a real life scenario if your not sure.
Reply
#6

Okay, thanks for explaining, m8 , of trying to help, btw I copied from wiki:
pawn Код:
new
    idx = 3;
 
if (0 < idx < 5)
{
    print("idx is greater than 0 and less than 5!");
}
Reply
#7

Quote:
Originally Posted by Cannary2048
Посмотреть сообщение
Okay, thanks for explaining, m8 , of trying to help, btw I copied from wiki:
pawn Код:
new
    idx = 3;
 
if (0 < idx < 5)
{
    print("idx is greater than 0 and less than 5!");
}
Okay, you've proved me wrong. I shall use this in the future... probably? +Rep for challenging me and being right! I love people that don't back down to high posters .
Reply
#8

Omg -_-
You don't need to oprimize it
And this isn't an optimization
Reply
#9

Also, it should be:
pawn Код:
if(!(6 < strlen(inputtext) < 24))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)