Return problem ? I think
#5

Quote:
Originally Posted by Troydere
Посмотреть сообщение
Allow me to de-structure your function

PHP код:
function
{
    
loop start
    
{
        
check if car id is a cop car (loop number 1)
        {
            if 
so stop the loop and the function itself and return 1;
        }
        if 
not
            stop the loop 
and the function itself and return 0;
    }
    return 
1although you wont reach here anyway

And that's what would happen in run-time, you have a loop although it will run only once, completely killing the purpose of the loop.

You can solve this by changing the value of the last return to 0, and removing the else statement and its contents. It'd look like this
PHP код:
function
{
    
loop
    
{
        
check if the car is a cop car
        
{
            if 
so, return 1;
        }
    }
    if 
the loop above did not find any carit did not stop the function, hence this return 0will pass

Ohhhh, now i get it , i was thiking i need that else there so it will return 0 but i was wrong , i don't know if you return 1 there will finish the loop and return 1 ..... Now it's clear why it was not worked
Reply


Messages In This Thread
Return problem ? I think - by Banditul18 - 02.04.2017, 19:15
Re: Return problem ? I think - by Toroi - 02.04.2017, 19:36
Re: Return problem ? I think - by Vince - 02.04.2017, 19:48
Re: Return problem ? I think - by GangstaSunny. - 02.04.2017, 19:54
Re: Return problem ? I think - by Banditul18 - 02.04.2017, 19:56
Re: Return problem ? I think - by Vince - 03.04.2017, 05:33
Re: Return problem ? I think - by GangstaSunny. - 03.04.2017, 08:08

Forum Jump:


Users browsing this thread: 2 Guest(s)