News:

;) This forum is the property of Proton software developers

Main Menu

What is the correct way to exit a procedure early?

Started by See_Mos, May 28, 2021, 04:40 PM

Previous topic - Next topic

See_Mos

Help please, I seem to be going around in circles with this.

What is the correct way to break out of a procedure early and return a value?

Simple example:-

If AA = BB Then Result = 175  Exit
Do some stuff
If BB = CC then Result = 232  Exit
Do loads of stuff
Result = XYZ
Endproc

trastikata

#1
Check p.41 from the manual. In your example I believe it should be like this:

Proc MyProc (), Byte
   If AA = BB Then Result = 175 : Return
   'Do some stuff
   If BB = CC then Result = 232 :  Return
   'Do loads of stuff
   Result = XYZ
Endproc

top204

See page 41 of the Positron8 compiler's manual.

The Return command can be replaced with the ExitProc command, which makes it a bit more clear as to what is happening within the procedure:

Proc MyProc(pBytein as Byte), Byte
    Result = pBytein                ' Transfer the parameter to the return variable
    If pBytein = 0 Then ExitProc    ' Perform a test and return early if required
    Result = Result + 1             ' Otherwise... Add one to it
EndProc

See_Mos

Thanks Les, once again I missed the obvious.  The printout of procedures was right in front of me as well.