Infinite While Loop

Scott

Usenet Archive
Joined
Feb 29, 2000
Messages
606
Reaction score
0
Hi everybody,

I was wondering if there was somebody out there that could explain why this while loop loops infinitely many times?

Here is the loop that is causing the problem:

(SETQ COUNT 100)
(WHILE (> COUNT 0)
(SETQ DCL_ID (LOAD_DIALOG "DIEISET1.dcl"))
(IF (NOT (NEW_DIALOG "DIEISET1" DCL_ID))
(EXIT)
)

(ACTION_TILE "stdscale" "(SETQ STDCHECK $VALUE)")
(ACTION_TILE "metscale" "(SETQ METCHECK $VALUE)")
(ACTION_TILE "settext" "(SETQ DIEITEXT $VALUE)")
(ACTION_TILE "setdim" "(SETQ DIEIDIM $VALUE)")
(ACTION_TILE "setvpscale" "(SETQ VPSCALE $VALUE)")
(ACTION_TILE "drawvp" "(SETQ MAKEVP $VALUE)")

(START_DIALOG)

(IF (OR (AND (/= STDCHECK 0) (/= METCHECK 0)) (OR (= STDCHECK METCHECK
0)))
(PROGN
(1- COUNT)
(PRINC "\nPLEASE CHOOSE EITHER A METRIC OR IMPERIAL SCALE") ) (PROGN (SETQ COUNT 0) (DONE_DIALOG) ) )
)

Thanks in advance for the help!

Scott McKenzie
 
(PROGN
(1- COUNT)
(PRINC "\nPLEASE CHOOSE EITHER A METRIC OR IMPERIAL SCALE")
)

Aside from the fact that this isn't a good way to
control the looping process, the expression (1- count)
does not change the value of the variable 'count', it
simply returns a value that is 1 less than the value
assigned to 'count'.

You have to assign the result to the symbol again:

(setq count (1- count))
 
Thanks for the help!

It seems that the loop runs 100 times even if all the user input is correct. Why would this be happening? The else part of the if statement does not seem to be working correctly, it is not redefining the count variable as 0?

Thanks again
 
It runs 100 times because you have an extra (or ...) in your (if ...) clause:
(IF (OR (AND (/= STDCHECK 0) (/= METCHECK 0)) (OR (= STDCHECK METCHECK 0)))

Try:
(IF (OR (AND (/= STDCHECK 0) (/= METCHECK 0)) (= STDCHECK METCHECK 0))
___

Scott said:
It seems that the loop runs 100 times even if all the user input is
correct.
 
This is what I have so far for my loop, it is still looping infinitely!

(SETQ STDCHECK 0)
(SETQ METCHECK 0)

(WHILE (OR (AND (/= STDCHECK 0) (/= METCHECK 0)) (= STDCHECK METCHECK 0))

(SETQ DCL_ID (LOAD_DIALOG "DIEISET1.dcl"))
(IF (NOT (NEW_DIALOG "DIEISET1" DCL_ID))
(PROGN
(PRINC "FAIL - UNABLE TO LOCATE DIEISET1.DCL")
(EXIT)
)
)

(ACTION_TILE "stdscale" "(SETQ STDCHECK $VALUE)")
(ACTION_TILE "metscale" "(SETQ METCHECK $VALUE)")
(ACTION_TILE "settext" "(SETQ DIEITEXT $VALUE)")
(ACTION_TILE "setdim" "(SETQ DIEIDIM $VALUE)")
(ACTION_TILE "setvpscale" "(SETQ VPSCALE $VALUE)")
(ACTION_TILE "drawvp" "(SETQ MAKEVP $VALUE)")

(START_DIALOG)
)

Thanks again to everybody that has had a look at this message/posting!
 
Hi,

Thanks for the idea. I removed the extra or as stated in your message to no avail. The loop still loops 100 times...

It's likely because your condition will is set up to look 100 times if both or neither variable is 0 (zero). One would have to be zero and the other not zero for it to exit.

Have you vertified that they are actual numerical values (not strings)? I don't recall what type of data $value returns because I rarely is ever use it due to bus I encountered with it years and years ago. I prefer otherways to validate the data coming out of a dialog.
 

Latest threads

Back
Top