Re: with entry and goto statement

new topic     » goto parent     » topic index » view thread      » older message » newer message
mexzony said...

did not quite get the explanation of the entry statement.

public function find_all ( object x, sequence source , integer from ) 
    sequence ret = {} 
 
    while from > 0 with entry do 
        ret &= from 
        from += 1 
    entry 
        from = find_from (x, source , from ) 
    end while 
    return ret 
end function 

With entry causes the while loop to skip its initial check (in this case from > 0) and jump directly to the entry statement on its first execution only. So, in this case the loop first executes from = find_from(x, source, from) before doing any condition check and before doing the ret &= from and from += 1 lines. This loop could be rewritten (for demo purposes) as:

from = find_from(x, source, from) 
while from > 0 do 
    ret &= from 
    from += 1 
    from = find_from(x, source, from) 
end while 

See how the with entry in this case eliminated the duplicate "initialization" code? In this case the "initialization" code and the "increment" code are the same, so a with entry makes sense as to remove the duplication.

Does that clear it up any?

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu