Discussion:
loops
(too old to reply)
earthling
2006-10-01 23:11:30 UTC
Permalink
how many loops are allowed within each other?
using pbcc3
Michael Mattias
2006-10-01 23:16:46 UTC
Permalink
Post by earthling
how many loops are allowed within each other?
using pbcc3
I never ran into a limit. My max depth of loop structures is maybe six or
seven. After that I get confused, primarily because I indent for each loop
and the source code starts exceeding the page width.

What did you have in mind?

MCM


.
earthling
2006-10-02 00:33:42 UTC
Permalink
Post by Michael Mattias
Post by earthling
how many loops are allowed within each other?
using pbcc3
I never ran into a limit. My max depth of loop structures is maybe six
or seven. After that I get confused, primarily because I indent for
each loop and the source code starts exceeding the page width.
What did you have in mind?
the following is 26 loops deep, how deep can you go? I am just
curious if there is a limit to the depth using the different
loops? DO/LOOP, FOR/NEXT. WHILE/WEND

FOR a=1 TO 2
FOR b=1 TO 2
FOR c=1 TO 2
FOR d=1 TO 2
FOR e=1 TO 2
FOR f=1 TO 2
FOR g=1 TO 2
FOR h=1 TO 2
FOR i=1 TO 2
FOR j=1 TO 2
FOR k=1 TO 2
FOR l=1 TO 2
FOR m=1 TO 2
FOR n=1 TO 2
FOR o=1 TO 2
FOR p=1 TO 2
FOR q=1 TO 2
FOR r=1 TO 2
FOR s=1 TO 2
FOR t=1 TO 2
FOR u=1 TO 2
FOR v=1 TO 2
FOR w=1 TO 2
FOR x=1 TO 2
FOR y=1 TO 2
FOR z=1 TO 2

NEXT z
NEXT y
NEXT x
NEXT w
NEXT v
NEXT u
NEXT t
NEXT s
NEXT r
NEXT q
NEXT p
NEXT o
NEXT n
NEXT m
NEXT l
NEXT k
NEXT j
NEXT i
NEXT h
NEXT g
NEXT f
NEXT e
NEXT d
NEXT c
NEXT b
NEXT a
Michael Mattias
2006-10-02 14:45:37 UTC
Permalink
Post by earthling
Post by Michael Mattias
Post by earthling
how many loops are allowed within each other?
using pbcc3
I never ran into a limit. My max depth of loop structures is maybe six
or seven. After that I get confused, primarily because I indent for
each loop and the source code starts exceeding the page width.
What did you have in mind?
the following is 26 loops deep, how deep can you go? I am just
curious if there is a limit to the depth using the different
loops? DO/LOOP, FOR/NEXT. WHILE/WEND
I don't believe there is any limit.

But if you want to confirm that, contact the publisher...that info is not in
the help file (not that I can find, anyway,

If you are an existing user of powerbasic products, write to
***@powerbasic.com
If you are not an existing user, I think I'd try ***@powerbasic.com

(FWIW, I've used PB compilers since 1991)

BTW, there is an interesting construct you could use..
For a = 1 to 2
For b = 1 to 2
....
for z = 1 to 2

Next, ,,,,,,,,,,,,,,,,,,,,,,,, (25 commas)
--
Michael C. Mattias
Tal Systems Inc.
Racine WI
***@talsystems.com
Lou
2006-10-02 15:44:55 UTC
Permalink
Post by Michael Mattias
Post by earthling
Post by Michael Mattias
Post by earthling
how many loops are allowed within each other?
using pbcc3
I never ran into a limit. My max depth of loop structures is maybe six
or seven. After that I get confused, primarily because I indent for
each loop and the source code starts exceeding the page width.
What did you have in mind?
the following is 26 loops deep, how deep can you go? I am just
curious if there is a limit to the depth using the different
loops? DO/LOOP, FOR/NEXT. WHILE/WEND
I don't believe there is any limit.
But if you want to confirm that, contact the publisher...that info is not in
the help file (not that I can find, anyway,
If you are an existing user of powerbasic products, write to
(FWIW, I've used PB compilers since 1991)
BTW, there is an interesting construct you could use..
For a = 1 to 2
For b = 1 to 2
....
for z = 1 to 2
Next, ,,,,,,,,,,,,,,,,,,,,,,,, (25 commas)
Come on MM. You are a good programmer. This retiree thinks there has
to be a better way <bg>

Lou
Michael Mattias
2006-10-02 15:53:44 UTC
Permalink
Post by Michael Mattias
BTW, there is an interesting construct you could use..
For a = 1 to 2
For b = 1 to 2
....
for z = 1 to 2
Next, ,,,,,,,,,,,,,,,,,,,,,,,, (25 commas)
Come on MM. You are a good programmer. This retiree thinks there has to
be a better way <bg>
And I agree with you. But as long as the question was 'how many loops deep'
I thought I'd address that directly.

Methinks Mr./Ms. Earthling (the OP) will discover soon enough that he/she
does not really want to write 26-deep nested loops. But better one should
learn the hard way, as I've found those are the lessons one remembers best.

MCM
Lou
2006-10-02 18:49:08 UTC
Permalink
Post by Michael Mattias
Post by Michael Mattias
BTW, there is an interesting construct you could use..
For a = 1 to 2
For b = 1 to 2
....
for z = 1 to 2
Next, ,,,,,,,,,,,,,,,,,,,,,,,, (25 commas)
Come on MM. You are a good programmer. This retiree thinks there has to
be a better way <bg>
And I agree with you. But as long as the question was 'how many loops deep'
I thought I'd address that directly.
Methinks Mr./Ms. Earthling (the OP) will discover soon enough that he/she
does not really want to write 26-deep nested loops. But better one should
learn the hard way, as I've found those are the lessons one remembers best.
MCM
How true!!

Lou
earthling
2006-10-03 01:49:51 UTC
Permalink
Post by Michael Mattias
Post by Lou
Post by Michael Mattias
BTW, there is an interesting construct you could use..
For a = 1 to 2
For b = 1 to 2
....
for z = 1 to 2
Next, ,,,,,,,,,,,,,,,,,,,,,,,, (25 commas)
Come on MM. You are a good programmer. This retiree thinks there
has to be a better way <bg>
And I agree with you. But as long as the question was 'how many loops
deep' I thought I'd address that directly.
Methinks Mr./Ms. Earthling (the OP) will discover soon enough that
he/she does not really want to write 26-deep nested loops. But better
one should learn the hard way, as I've found those are the lessons one
remembers best.
26-deep nested loops was just an example.
this could be more/less.

still not an answer to the question as to how deep one
can have nested loops.
Michael Mattias
2006-10-03 11:43:10 UTC
Permalink
Post by earthling
still not an answer to the question as to how deep one
can have nested loops.
I gave you the best possible answer: since you are a PB/CC user, you should
contact ***@powerbasic.com and ask them.

MCM
earthling
2006-10-03 01:56:55 UTC
Permalink
Post by Lou
Post by Michael Mattias
Post by earthling
Post by Michael Mattias
Post by earthling
how many loops are allowed within each other?
using pbcc3
I never ran into a limit. My max depth of loop structures is maybe
six or seven. After that I get confused, primarily because I indent
for each loop and the source code starts exceeding the page width.
What did you have in mind?
the following is 26 loops deep, how deep can you go? I am just
curious if there is a limit to the depth using the different
loops? DO/LOOP, FOR/NEXT. WHILE/WEND
I don't believe there is any limit.
But if you want to confirm that, contact the publisher...that info is
not in the help file (not that I can find, anyway,
If you are an existing user of powerbasic products, write to
(FWIW, I've used PB compilers since 1991)
BTW, there is an interesting construct you could use..
For a = 1 to 2
For b = 1 to 2
....
for z = 1 to 2
Next, ,,,,,,,,,,,,,,,,,,,,,,,, (25 commas)
Come on MM. You are a good programmer. This retiree thinks there has
to be a better way <bg>
that was just a short example. there is code that is run between
each for/next that is applied to the next loop or skips the next loop.

if there is a better way then please do elaborate...
James Beck
2006-10-03 14:43:21 UTC
Permalink
Post by earthling
that was just a short example. there is code that is run between
each for/next that is applied to the next loop or skips the next loop.
if there is a better way then please do elaborate...
I think the point is that if you are nesting loops to the depth that you
are worried about running up against some compiler limitation then you
had better rethink the problem.
Jonathan Berry
2006-10-03 16:04:01 UTC
Permalink
Warning: OT

In 1979 I attempted to program a double entry accounting system
for a small organization, using CBASIC (a structured, p-code
BASIC) on a CP/M machine with 64K RAM (that's K not Meg).

I tested it out, but every time after about a screen worth of
entries, it would crash. I couldn't figure out what the matter
was, so I went on to another needed programming task, and
wisely chose to use a different "style" of programming.

Years later a colleague debugged the situation. I had used a
lot of GOSUBs. Each time a GOSUB was called, the language
would push the address onto the stack. It turned out that the
CBASIC "stack" had enough space for 19 GOSUBs (without RETURN)
and then it would go haywire. I don't remember the exact term
for the crash, it might have been "hammering the stack" or
"blowing the stack". I suppose you'd get a similar behaviour
with excessive loops.

CBASIC was so precisely described in the large-format blue
manual that came with it, that I actually was surprised that
the publishers had not warned about the dangers in that style
of programming. Those were the days.

I never again used GOSUBs (well, hardly ever), relying instead
on functions, with happy results.

Digital Research later purchased CBASIC (I think that Gordon
Eubanks came with), and produced CBASIC86 (would run under
DOS or CP/M86) and CB86 (compiled rather than p-code). The
same colleague told me that "porting" a working CBASIC program
from CP/M-80 to DOS (and a different family of processors) was
usually as simple as recompiling the source code.



--
happy
Jonathan Berry and Erika http://members.shaw.ca/berry5868/fun.htm
Stan Helton
2006-10-03 01:56:42 UTC
Permalink
Post by earthling
how many loops are allowed within each other?
using pbcc3
For PB/DOS the limit is 64. I have not found any documentation on this in
PB/WIN.
Stan
Jeff Slarve
2006-10-03 02:16:19 UTC
Permalink
Nested loops are kinda ugly and difficult to maintain. Try thinking of
a re-usable recursive function. Much less code to write and maintain.

I'm not a powerbasic expert by any means, but I think the above would
hold true in just about any language.
Post by earthling
how many loops are allowed within each other?
using pbcc3
Loading...