Switch question
#1

Hello, i have a question about switch thing, i know it used instead of if statemante but i don't know how to make this
Код:
 new pd = APlayerData[playerid][StatsPoliceFined];

			if(pd >= 0 && pd <= 50) rank = "Benginer Policeman";
			else if (pd >= 51 && pd <= 100) rank = "Advanced Policeman";
			else if (pd >= 101 && pd <= 200) rank = "Expert Policeman";
			else if (pd >= 201 && pd <= 500) rank = "Underboss Policeman";
			else if (pd >= 500) rank = "Police Big Boss";
With switch, but no all thing, i mean the last else-if statemante
Код:
 switch(pd)
			{
				case 0 .. 50: rank = "Benginer Policeman";
				case 51 .. 100: rank = "Advanced Policeman";
				case 101 .. 200: rank = "Expert Policeman";
				case 201 .. 500: rank = "Underboss Policeman";
				case 500  //this how to make to be > 500?
			}
Reply
#2

Use if for that.
Reply
#3

Using default will work
PHP код:
default: //your code 
but i think you should careful with negative values if there is no chance of that then you dont have to worry.
Reply
#4

Yep. Sreyas is right. Make sure before the switch, you have an if statement with return something if the value is negative to avoid problems.
Reply
#5

There will be no negative values , and thanks i was thinking there was a special case for that , i didn't thinking at default case... Many thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)