Posts: 136
Threads: 7
Joined: Jun 2007
I tried to program the N-Queens Problem on the HP-9G for benchmarking and get a "NEST Er" without a plausible reason. After invastigating the problem, I have found the following:
N=3
S=0
Lbl 0:
S=S+N
IF(--N)THEN{GOTO 0}
PRINT S
This simple program for the sum of 1..n works only to N=3. The reason seems to be the jump out of the IF block more than 3 times.
Is it possible to avoid this problem?
Posts: 1,841
Threads: 54
Joined: Jul 2005
Hi,
did you try other variable names?
Did you try with discrete operations,
like N=N-1 instead of '(--N)' ?
What does the doc say about that 'GOTO 0' construct ?
Or about the error message?
A nesting error indicates that either calling the
subprogram would exceed the the allowed nesting depth,
or maybe you forgot the correct return statement.
Raymond
Posts: 136
Threads: 7
Joined: Jun 2007
I have tried N=N-1 or other variables too. The "NEST Er" is discribed in the manual for the GOSUB statement with a maximum of 3 nesting depth.
Another example:
N=0
Lbl 0:
IF(1)THEN{N=N+1}
GOTO 0
N=0
Lbl0:
IF(1)THEN{N=N+1;GOTO 0}
The first example works but the second gives a "NEST Er".