midrange.com code scratchpad |
Name:
Dennis Lovelady
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
03/02/2010 06:16:21 pm
|
IP:
Logged
|
|
Description:
// This routine is a shell to demonstrate alternative
// methods of leaving a procedure early. It expoits
// the RPG opcode LEAVE, which will exit a loop
// prematurely without breaking structured programming
// protocol
// This approach doesn't add unnecessary condition tests
// to the flow - that is as clean as any alternative. It
// also adheres to the "one entry / one exit" standard of
// programming.
|
Code:
- /Free
-
- P myProc B
- D PI 10I 0
- D parm1 8 Const
-
- D once S 3U 0
- D rtnValue S Like(myProc)
-
- /Free
-
- // This routine is a shell to demonstrate alternative
- // methods of leaving a procedure early. It expoits
- // the RPG opcode LEAVE, which will exit a loop
- // prematurely without breaking structured programming
- // protocol
-
- // This approach doesn't add unnecessary condition tests
- // to the flow - that is as clean as any alternative. It
- // also adheres to the "one entry / one exit" standard of
- // programming.
-
- rtnValue = -9999 ;
- For once = 1 to 1 ;
- // Stuff
- // Oops - an error is found. We gotta get out.
- If oops ;
- // do stuff
- rtnValue = -1 ;
- Leave ;
- EndIF ;
- // More stuff
- // More stuff
- If oopsToo ;
- // do stuff
- rtnValue = -2 ;
- Leave ;
- EndIF ;
- rtnValue = *Zero ;
- EndDO ;
- // Cleanup
- Return rtnValue ;
-
- /End-free
-
- P myProc B
|
|
|