1.38. Procedure return
A procedure can be terminated by a goto to a label
at the end of the procedure:
Start felix section to tut/examples/tut_beg146.flx[1
/1
]
1: #line 2081 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int)
5: {
6: if x == 0 goto zero;
7: print x; endl;
8: goto finished;
9: zero:>
10: print "Zero"; endl;
11: finished:>
12: }
13:
14: f(1);
15: f(0);
A slightly more structured way of doing this
involves the procedural return statement:
Start felix section to tut/examples/tut_beg147.flx[1
/1
]
1: #line 2099 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int)
5: {
6: if x == 0 goto zero;
7: print x; endl;
8: return;
9: zero:>
10: print "Zero"; endl;
11: }
12:
13: f(1);
14: f(0);
15:
This can also be shortened by using a the jump statement:
Start felix section to tut/examples/tut_beg148.flx[1
/1
]
1: #line 2116 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int)
5: {
6: if x == 0 goto zero;
7: print x; jump endl;
8: zero:>
9: print "Zero"; jump endl;
10: }
11:
12: f(1);
13: f(0);
14:
which is equivalent to a call statement followed by a
return, which in turn is equivalent to a call
followed by a goto the end of the procedure.