John Baro said:
Is there any way of getting a directory structure of unlimited levels
without using recursion?
GOTO is not an option.
Hmmm, why is GOTO not an option? Are you forbidden to use it by a
fetishistic boss? I coded two C# goto statements just last night... (With
comments saying I'm a professor of computer science and nobody can tell me
not to!
What you are wanting to do is a tree search. If you can't write recursive
procedures, then the other way to do it is to maintain a list of directories
you're going to search. Initially it contains only the current directory.
Find the directories in it and add them to the end of the list. Keep going,
and keep doing the same thing. Or add them at the beginning, if you'd
rather have a depth-first search.
More generally: Any recursive algorithm can be implemented without
recursion, by using additional lists or stacks. After all, there is no
recursion in machine language; the compiler has to translate the recursion
into something else. The Pentium has stacks in machine language, but some
other machines I've used (e.g., CDC CYBER) do not. Just more work for the
compiler.
In the *really* old days (pre-1980 or so) most programming languages did not
allow you to write recursive procedures. Try writing an expression
evaluator in FORTRAN. I did; I think it had 3 stacks.