Re: goto's, and loops
- Posted by "Lucius L. Hilley III" <lhilley at CDC.NET> Jul 30, 1999
- 560 views
WARNING: Pseudo-code follows. A goto statement has two uses. 1. skip code. integer h -- file handle h = open("somefile", "r") if h = -1 then --file not opened goto Skip end if load_opened_file() :Skip do_other_things() 2. repeat code. :Repeat puts(1, "This keeps printing...") goto Repeat Skip code can be accomplished with of the following if statements. if flag then do_code() end if if flag then do_code() else do_other_code() end if if flag1 then do_code1() elsif flag2 then do_code2() end if if flag1 then do_code1() elsif flag2 then do_code2() else do_other_code() end if Repeat code is handled with a while loop. while 1 do do_code() if exit_now then exit end if do_more_code() end while the exit can be placed anywhere and will only exit that loop. The only way to exit nested loops is with flags for each loop. integer end_loop1, end_loop2, end_loop3 end_loop1 = repeat(0, 3) while 1 do --loop1 while 1 do --loop2 while 1 do --loop3 end_loop1 = 1 exit end while --end_loop3 if end_loop1 or end_loop2 then exit end if end while --end_loop2 if end_loop1 then exit end if end while --end_loop1 Lucius L. Hilley III lhilley at cdc.net lucius at ComputerCafeUSA.com +----------+--------------+--------------+----------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | Computer | | Horse +--------------+--------------+ Cafe' | | Software | http://www.cdc.net/~lhilley | USA | +----------+-------+---------------------+----------+ | http://www.ComputerCafeUSA.com | +--------------------------------+