1. Re: Short Circuiting + Return in procedures
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Jun 26, 1998
- 563 views
On Thu, 25 Jun 1998, Terry Constant wrote: > to jump to the next iteration of a loop without having to go through the > rest of the code before getting to the end of the loop. > > For example, > > for i = 1 to 1000 do > if s[i] is not what I am looking for then > loop > end if Reverse your logic and it is done: for index = start to finish by step do if data[index] = what_you_want then -- note '=' rather than '!=' exit end if end for :) As for the argument over exit, return and abort(), each is a stronger version of the previous. For instance, in the above for-loop, the exit causes the for-loop to drop what it is doing and run the code following it. If the "exit" is replaced by a "return", the subroutine (I assume, this time, that it is *in* a subroutine) will drop what it is doing and run the code following the subroutine call. If the "exit" is replaced by an "abort()", the *whole program* drops what it is doing and returns to the OS. Hence the need for different code in each situation. If "exit" was the only keyword, then it becomes ambigiuous... Carl PS Yes, I've used QBasic. IK that EXIT FUNCTION is used, but the syntax for returning a value is horrible. -- Carl R White E-mail...: cyrek- at -bigfoot.com / Remove the hyphens before Finger...: crwhite- at -dcsun1.comp.brad.ac.uk \ mailing or fingering... Url......: http://www.bigfoot.com/~cyrek/