Return from nested subroutines (still goto discussion)

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

Code..
(I used to use this in PASCAL long time ago)


procedure r(integer x)
    if x = 5 then
        puts(1, "success")
        goto ok
    end if
    r(x+1)
    puts(1, "don't come here!")
end procedure

procedure main()
    r(1)
ok:
    puts(1, "program end")
end procedure


When  main() is executed, it will call r(1), r(1) will call r(2), etc,
r(4)  will call r(5), r(5) will print "success" and then goto ok which
will print "program end" without no printing of "don't come here!"

That  is  the  very  convenient  use  of goto, and I used goto only on
programs like that.

Is  there  any  method  to  perform the same as above without goto and
without decreasing performance?

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

Search



Quick Links

User menu

Not signed in.

Misc Menu