GETINT and comparison operators

GETINT and comparison operators

Browning_Zed
Advocate Advocate
724 Views
2 Replies
Message 1 of 3

GETINT and comparison operators

Browning_Zed
Advocate
Advocate

Hello everyone,
Using the GETINT function, I can set some conditions for entering numbers using the INITGET function, like this:
(initget 6) (getint "input integer: ")
But what if I want to add comparison operators to this combination? For example, the input integer should also be:
(and (/= 1 input_integer) (> 10 input_integer))
How can I do this?

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

Kent1Cooper
Consultant
Consultant
Accepted solution

The usual way:  get input in a (while) loop, do the comparison(s), and if unacceptable, go back:

 

(while

  (and

    (not (initget 6)); no zero, no negative [(not) wrapper because (initget) always returns nil]

    (setq xyz (getint "\nInput positive integer smaller than 10 but not 1: "))

    (or (= xyz 1) (>= xyz 10))

  )

  (prompt "\nNot an acceptable value -- try again.")

)

 

or

 

(while

  (and

    (not (initget 6)); no zero, no negative

    (setq xyz (getint "\nInput positive integer between 2 and 9: "))

    (not (< 1 xyz 10))

  )

  (prompt "\nNot an acceptable value -- try again.")

)

Kent Cooper, AIA
Message 3 of 3

Browning_Zed
Advocate
Advocate

Thank you for your help.

0 Likes