Re: The fate of Euphoria
- Posted by Patrick Barnes <mrtrick at gmail.com> Nov 08, 2004
- 570 views
> Patrick: > Where did you find " next(N) " instruction ? > > Bernie I said... *IF* they are available. Unfortunately Rob hasn't implemented all of the high-level program flow constructs.
for a = 1 to 10 do *lots of code* if something then [I want to skip the rest of the block, but stay within the loop] end if *lots more code* end for
At the moment, we have to encase the 'lots more code' within an if statement. Unfortunately, this often leads to horrible amounts of indenting. In C and Java, the 'continue' statement causes the program to start executing again at the beginning of the loop, incrementing the loop variable. In Euphoria, hopefully ''next' or 'continue' could do the same thing... The other thing missing is control over the exit/next statement's scope. If you have this:
for x = 1 to SCREEN_WIDTH do for y = 1 to SCREEN_HEIGHT do *code* *code* [I've found what I'm looking for, I want to exit out of these 'for' loops] *code* end for end for
Using just plain 'exit' won't work. You need to do this:
integer exit_flag exit_flag = 0 for x = 1 to SCREEN_WIDTH do for y = 1 to SCREEN_HEIGHT do *code* *code* --[I've found what I'm looking for, I want to exit out of these 'for' loops] if something_is_true then exit_flag = 1 exit end if *code* end for if exit_flag then exit end if end for
Not only is it harder to understand, it is slower, because the program has to keep checking exit_flag every time it iterates through... Adding something like exit(N), where N is the number of loops to exit out of, would make life much easier. If there are concerns about readability, loops could be given an OPTIONAL label: for x = 1 to 10 as outer_x do OR while 1 as main_loop do. That way, exit( label ) would move out of the loop with that label, and continue executing code right after the end for / end while of that loop. (label is not of any type, and cannot be read, written, or referred to in any other way.) -- MrTrick