AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Skip some number using While (https://forums.alliedmods.net/showthread.php?t=244612)

anon12 07-21-2014 02:44

Skip some number using While
 
How can I skip a certain number using Whileloop?

Example:
It will loop a number from 1 -500 however I don't want 200-300 to be counted.

Black Rose 07-21-2014 03:14

Re: Skip some number using While
 
Code:
for ( new i = 1 ; i <= 500 ; i++ ) {     if ( i == 200 )         i = 301; }

anon12 07-21-2014 04:20

Re: Skip some number using While
 
Thanks,

I have this, but it still creates a number from 1 to 649. Why is that? :/
PHP Code:

new i=0;
    while( 
i<=649/12)
    {
        if( (
12*i)+== 388)
        {
            
493
        
}
        if( (
12*i)+>= 649)
            break;
            
        
menu_additemmenui+1"\\w%L (Image from:%d to: %d)"id,"TXT_MENU", (12*i)+1min((12*i)+12,649));
        
i++;



fysiks 07-21-2014 05:07

Re: Skip some number using While
 
Your code doesn't even compile . . .

You need to look at the definition of the menu_additem() function.
Why are you doing a whole bunch of multiplying? It is entirely unnecessary.

Explain EXACTLY what you are trying to do.

P.S. (12*i)+1 is ALWAYS an odd number and will therefore never be equal to 388. However, this is a moot point because you are are doing this very wrong.

Backstabnoob 07-21-2014 05:09

Re: Skip some number using While
 
12*i+1 can't be 388. Your code is very confusing

Bladell 07-21-2014 09:46

Re: Skip some number using While
 
Code:

new i = 0

while(i <= 500)
{
        i++
       
        if(i >= 200 && i <= 300)
                continue
               
        //some code
}

or

Code:

new i = 0

while(i <= 500)
{
        i++
       
        if(i >= 200 && i <= 300)
                i = 301
               
        //some code
}


Black Rose 07-21-2014 10:56

Re: Skip some number using While
 
The second one generates less loops.
My example is still better.
I suggest using a for loop for all incremental type of loops.
While loops are generally used in combination with functions that work with a more true/false statement ( != 0 or == 0 ), for example feof().


All times are GMT -4. The time now is 13:19.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.