do while (true); // Getting rid of warnings / Alternative? -
TheXIII - 10.11.2010
pawn Код:
public FindSkin(gender, skin, price){
new skinid;
do
{
skinid = random(300);
if( SkinDB[skinid][Gender] == gender && SkinDB[skinid][Skin] == skin && SkinDB[skinid][Price] == price ) break;
}
while( true ); // warning 206: redundant test: constant expression is non-zero
return skinid; // warning 225: unreachable code
}
Now, this code functions like it should, and does what needed. However, it puts out two warnings, stated in the code as comments. What is the best way to get rid of them. Or what would be a better, more optimal way to do this?
Re: do while (true); // Getting rid of warnings / Alternative? -
Sergei - 10.11.2010
Код:
public FindSkin(gender, skin, price){
new skinid;
for(;;)
{
skinid = random(300);
if( SkinDB[skinid][Gender] == gender && SkinDB[skinid][Skin] == skin && SkinDB[skinid][Price] == price ) break;
}
return skinid; // warning 225: unreachable code
}
Re: do while (true); // Getting rid of warnings / Alternative? -
TheXIII - 10.11.2010
Heh, didn't know this would work. Thanks
Re: do while (true); // Getting rid of warnings / Alternative? -
Jakku - 10.11.2010
Must add: Pawn- language has not the
do-while- function like Java does
Re: do while (true); // Getting rid of warnings / Alternative? -
Sinner - 10.11.2010
Why would you do do-while? Since while doesn't have a statement for which it shouldn't run there is no need to "do" something first right?
Does exactly the same as
Re: do while (true); // Getting rid of warnings / Alternative? -
Slice - 10.11.2010
You
could do:
pawn Код:
public FindSkin(gender, skin, price)
{
new skinid;
loop:
skinid = random( 300 );
if ( SkinDB[skinid][Gender] == gender && SkinDB[skinid][Skin] == skin && SkinDB[skinid][Price] == price )
return skinid;
goto loop;
}
Re: do while (true); // Getting rid of warnings / Alternative? -
TheXIII - 10.11.2010
Well, at first I did use do-while loop with a valid condition, kinda like ****** posted. Exact code was ( I think ):
pawn Код:
do
{
skinid = random(300);
}
while (SkinDB[skinid][Gender] != gender && SkinDB[skinid][Skin] != skin && SkinDB[skinid][Price] != price);
But this didn't work like its supposed to. It have me a wrong skinID. I figured it did a loop one more time, and returned the next random value instead. Maybe, there was some other mistake..
The truth is, I'm a bit ill today, and it's kind of hard to focus. So some stupid little mistakes are keen to come. Still, I wish to get something done despite it.
The code will be used only once, when the player registers. All of the
gender/skin combinations are there, and the
price variable is there for another reason, for later. For now, the function will only search for skins with the price of -1. So there shouldn't be a condition where the loop can't break.
For now I will stick with the infinite
for loop, as it's something new for me, and it works

I doubt there's much room for optimization anyway. ( I hope someone proves me wrong here :P )
Re: do while (true); // Getting rid of warnings / Alternative? -
TheXIII - 10.11.2010
Ah, I see. Thanks for the help, everyone
Re: do while (true); // Getting rid of warnings / Alternative? -
legodude - 10.11.2010
omfg ***** ur really smart
you are pawn's (andwhatnototherlangs) einstein with a little touch of aristotle and some pythagoras topping with as desert some galilei-gelly(lol those look like eachother)