New to Loops such as these ones, any advice?
#1

This function is to get the Free Biz ID in my Database... (well actually it doesnt read the database)
Ex: I have BIZ ids 1,2,3,5: Output: Biz ID 4 is free.
This is what the loop looks like and I am just wondering if there's a smarter way to do this, it works right now though.

But I don't think it'll work if I change it in realtime, as the Array's ID's will change if I add ID 4 in, and delete ID 2, my result may not output 2....
PHP Code:
GetFreeBizID()
{
    new 
ResultLastID;
    for(new 
0MAX_BIZSi++)
    {
        if(
== 0)
        {
            
printf("Iteration [%i]"i);//Result 0
            
printf("DynamicBizs[i][ID]: [%i]"DynamicBizs[i][ID]);// Result 1
            
LastID DynamicBizs[i][ID];
            continue;
        }
        if(
LastID == DynamicBizs[i][ID]-&& DynamicBizs[i][ID] == LastID +1)
        {
            
LastID DynamicBizs[i][ID];
            
printf("Iteration [%i]"i);//Result 0
            
printf("DynamicBizs[i][ID]: [%i]"DynamicBizs[i][ID]);// Result 1
            
continue;
        }
        if(
LastID == DynamicBizs[i][ID]-2)
        {
            
Result i+1;
            break;
        }
    }
    
printf("GetFreeBizID Result: %i"Result);
    return 
Result;

Reply


Messages In This Thread
New to Loops such as these ones, any advice? - by SkyFlare - 18.07.2020, 06:34
Re: New to Loops such as these ones, any advice? - by grymtn - 18.07.2020, 07:43
Re: New to Loops such as these ones, any advice? - by GameOvr - 18.07.2020, 08:01
Re: New to Loops such as these ones, any advice? - by SkyFlare - 18.07.2020, 08:11
Re: New to Loops such as these ones, any advice? - by xRadical3 - 18.07.2020, 08:48

Forum Jump:


Users browsing this thread: 1 Guest(s)