Re: Use of nested loops.
From: Peter Pichler (pichlo6_at_pobox.sk)
Date: 11/03/03
- Next message: Peter Pichler: "Re: bivariate interpolation"
- Previous message: Sheldon Simms: "Re: more hand written integer pow() functions (LONG POST)"
- In reply to: Keith Thompson: "Re: Use of nested loops."
- Next in thread: Neptune: "Re: Use of nested loops."
- Reply: Neptune: "Re: Use of nested loops."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 3 Nov 2003 22:15:38 -0000
"Keith Thompson" <kst@cts.com> wrote in message
news:lzism1qhh4.fsf@cts.com...
> BTW, another example of a nested loop might be reading lines from a
> file, and processing each character in each line. You might use a
> triple-nested loop to open each of the files named on the command
> line, reading each line from each file, and processing each character
> on each line.
Neptune, in many cases you use multiple nested loops without even knowing
it.
Let's look at Keith's a modified example. Open a text file and read and
print
each line. You need a loop in which to read a line, test you have
successfully
read it and then print it. Inside that loop, you would probably use fgets
for
reading and puts or printf for printing. Each of these functions contains at
least one loop, possibly more than one. So, you may get nested loops simply
by
calling a function in a loop. Isn't programming fun :-)
To answer your original question, nested loops are used whenever an
algorithm
asks for it. Processing more than one-dimensional entities is the most
common
example. My example is one of them: the line number could be considered the
vertical and the position of a character in a line the horizontal dimension.
- Next message: Peter Pichler: "Re: bivariate interpolation"
- Previous message: Sheldon Simms: "Re: more hand written integer pow() functions (LONG POST)"
- In reply to: Keith Thompson: "Re: Use of nested loops."
- Next in thread: Neptune: "Re: Use of nested loops."
- Reply: Neptune: "Re: Use of nested loops."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|