Next: Computing square roots
Up: Loops
Previous: Loops

Searching in an Array

Suppose that you are asked to write a function to determine whether or not a particular number is stored in a particular array. Take a look at ``search1.f'' in your ``examples'' directory (or view it directly) for an example of such a program.

Study the function until you can answer the following questions.

Many modern programming languages have an ``EXIT'' statement that accomplishes exactly what this GOTO does. It provides a structured way of breaking out of a loop.

There's actually a way to implement the ``SEARCH'' function without using a GOTO. (And everything else being equal, it's always nice to avoid using GOTO's.) Can you find the way. (Hint: make a creative use of ``RETURN''.)

Click here for the answer

Take a look at ``search2.f'' (or view it directly) for a version of the SEARCH function that is modified along these lines.


Next: Computing square roots
Up: Loops
Previous: Loops

Hamlet Project
hamlet@cs.utah.edu