Re: Goto, etc.
- Posted by Michael Nelson <mike-nelson-ODAAT at WORLDNET.ATT.NET> Nov 16, 1999
- 457 views
------=_NextPart_000_00DC_01BF300C.87E2ED00 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable A possible simpler solution to exiting nested blocks with no goto's or = labels: exit could be modified to take an (optional) integer argument (1 assumed = if omitted). The agument would specify the number of nesting levels to = exit: --Psuedo-code-- for i=3D1 to 10 do for j=3D5 to 25 by 5 do while k<75 do if error1 then exit end if -- or exit 1 if error2 then exit 2 end if if error3 then exit 3 end if end while end for end for when error1 occcurs, only the inner block is exited, when error2 occurs, = the inner block and the enclosing for block is exited, if error3, then = all blocks are exited. This is just an off the top of my head idea--what do you think about it? --Mike Nelson ------=_NextPart_000_00DC_01BF300C.87E2ED00 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD> <META content=3Dtext/html;charset=3Diso-8859-1 = http-equiv=3DContent-Type> <META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT color=3D#000000 size=3D2>A possible simpler solution to = exiting nested=20 blocks with no goto's or labels:</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 size=3D2>exit could be modified to take an = (optional)=20 integer argument (1 assumed if omitted). The agument would specify = the=20 number of nesting levels to exit:</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 size=3D2>--Psuedo-code--</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 size=3D2>for i=3D1 to 10 do</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2> for j=3D5 to 25 = by 5=20 do</FONT></DIV> <DIV><FONT color=3D#000000 = size=3D2> while=20 k<75 do</FONT></DIV> <DIV><FONT color=3D#000000=20 p; if=20 error1 then exit end if -- or exit 1</FONT></DIV> <DIV><FONT color=3D#000000=20 p; if=20 error2 then exit 2 end if</FONT></DIV> <DIV><FONT color=3D#000000=20 p; if=20 error3 then exit 3 end if</FONT></DIV> <DIV><FONT color=3D#000000 = size=3D2> end=20 while</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2> end = for</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT><FONT size=3D2>end = for</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>when error1 occcurs, only the inner block is exited, = when=20 error2 occurs, the inner block and the enclosing for block is exited, if = error3,=20 then all blocks are exited.</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>This is just an off the top of my head idea--what do = you think=20 about it?</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV><FONT size=3D2>--Mike Nelson</FONT></DIV> ------=_NextPart_000_00DC_01BF300C.87E2ED00--