Infinite While Loop

Discussion in 'AutoCAD' started by Scott, Jul 11, 2003.

  1. Scott

    Scott Guest

    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
     
    Scott, Jul 11, 2003
    #1
  2. (PROGN
    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))
     
    Tony Tanzillo, Jul 11, 2003
    #2
  3. Scott

    Scott Guest

    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
     
    Scott, Jul 12, 2003
    #3
  4. Scott

    Paul Turvill Guest

    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))
    ___

    correct.
     
    Paul Turvill, Jul 12, 2003
    #4
  5. Scott

    Scott Guest

    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!
     
    Scott, Jul 14, 2003
    #5
  6. 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.


    --

    Darren J. Young


    Autodesk Developer Network
    AUGI Inventor Product Chair

    Minnesota CADWorks, Inc.
    PO Box 1172
    Monticello, Minnesota 55362-1172
    (763) 295-4433
    http://www.mcwi.com
    ftp://ftp.mcwi.com
     
    Darren J. Young, Jul 16, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.