Re: EOF and GOTO and 0th array element
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 22, 2002
- 517 views
----- Original Message ----- From: "darceman" <darce at ffi.com> To: "EUforum" <EUforum at topica.com> Subject: EOF and GOTO and 0th array element > > 1. What is the equivalent to a BASIC EOF (end-of-file) marker that I can > test for? > > My current solution for #1 - when inputing a list from a text file with: > > object dd, f1 > > dd=get(f1) > > At the end of the file, atom(dd) returns a zero, which I use to check > for an end-of-file marker. Is there a more "proper" way? That is the proper way in Euphoria. > > 2. At the risk of incurring wrath for writing spaghetti code, is there a > GOTO equivalent? Yes and no. Strictly speaking there is no GOTO (thankfully). However, if you wish to write hard-to-read and hard-to-maintain code, Euphoria still allows this option. GOTO can be emulated using a state machine concept. function routine_1() -- do some work return 2 end function function routine_2() -- do some work if xyz then return 3 else return 2 end if end function function routine_3() -- do some work if abc then return 2 else return 1 end if end function function routine_4() -- do some work if qwerty then return 4 else if ytrewq then return 1 end if -- do more work if ytrewq then return 3 else return 0 end if end if end function -- State Machine -- x = 0 state = 1 while x != -1 do x = routine_id(sprintf("routine_%d", state)) if x != -1 then state = call_func(x,{}) end if end while > 3. in BASIC an array can be created with 0th (zeroth?) element in any > dimension, but I don't see how you can do that in a sequence. Can one > set up a Euphoric equivalent to such an element in a sequence? No. Euphoria uses a 1-based index philosophy. The first element in a series is always 1. Oh, except for routine_id(). Oh, and open() as well. > 4. Nested in a while...end while loop is a for..end for loop. If a > test fails in the for..end for loop I want to exit the while..end while > loop. However, using exit command in the for..end for loop seems to > only exit the "for" loop and does not apply to the "while" loop. Can > one indicate what to exit if using that command, or (as in the example > below) do I have to set some condition in the "for" loop to test outside > of it in order to exit the "while" loop? > > . > . > somemarker=true > while 1 do > . > . > -- test values; if fail, exit loop > for y=1 to 10 do > if test y fails then > somemarker=false > exit > end if > end for > if somemarker=false then > exit > end if > . > . > end while > . > . > This request just keeps on coming up. Euphoria doesn't make it easy for us. It encourages hard-to-read code in this instance. My "pet" solution is a form of controlled GOTO. somemarker: while 1 do . . -- test values; if fail, exit loop for y=1 to 10 do if test y fails then exit somemarker end if end for . . end while ---------------- cheers, Derek Parnell