Exit a While when User enter?

Exit a While when User enter?

Anonymous
Not applicable
1,676 Views
2 Replies
Message 1 of 3

Exit a While when User enter?

Anonymous
Not applicable

When user press botton Enter, I could exit while.

0 Likes
Accepted solutions (1)
1,677 Views
2 Replies
Replies (2)
Message 2 of 3

pbejse
Mentor
Mentor

@Anonymous wrote:

When user press botton Enter, I could exit while.


Any of the get function can do that for you, what do you have in mind?

 

 

 

Message 3 of 3

john.uhden
Mentor
Mentor
Accepted solution

Most any function that requires user input can be used to stop a while loop, e.g.

 

(while (setq p (getpoint "\nNext point: "))
  (do_this)
  (do_that)
)

But hitting Enter for a (getstring) will return an empty string (""), so...

(while (/= (setq str (getstring "\nText: ")) "")
  (do_this)
)

I recommend you test each function to see what a null response returns.

Or what I often do (presuming Done is local and not set)...

 

(while (not Done)
  (setq ans (getstring "\nEnter ID: "))
  (cond
    ((= ans "JFU")(do_this ans))
    ((= ans "MLK")(do_that ans))
    ((= ans "")(setq Done 1))
  )
)

John F. Uhden