PDA

View Full Version : Repeating a function until a given input



mbrandt5
2015-05-14, 02:00 PM
So, I have a function that does a series of events

Defun C:Function

(If Some Code

)


I would like this to be prompted to occur again with options of Yes or No
pushing just the N for no or Y for yes would be nice but not a necessity...

So it would ask something like \Would you like to do this again?

Then you could enter a string of Yes or No

Tharwat
2015-05-14, 07:32 PM
Hi,

Have a look about the following codes .



(initget 7 "Yes No")
(setq kw (getkword "\nWould you like to do it again [Yes,No] :"))

mbrandt5
2015-05-15, 02:25 AM
Thanks for pointing me in that direction...I found ronleighs page describing that code, but not sure now how I execute a loop or while or repeat if any Pointers

Tharwat
2015-05-15, 08:10 AM
One way ...



(while
(and (not (initget 7 "Yes No"))
(setq kw (getkword "\nWould you like to do it again [Yes,No] :"))
(eq kw "Yes")
)
( ;; Do some stuff here ;;
)
)

mbrandt5
2015-05-15, 11:32 AM
So if I'm not mistaken whenever kw is changed to yes it will jump to that given while test

Tharwat
2015-05-15, 06:21 PM
So if I'm not mistaken whenever kw is changed to yes it will jump to that given while test

If the input keyword is equal to Yes , the routine should keep on doing the stuff, otherwise it would exit safely with no error .

mbrandt5
2015-05-15, 07:58 PM
for more of a while wend function like in vba

For example while kw= yes then resume code here...(this at the beginning of code)

Then at the end have something like...


(initget 7 "Yes No")
(setq kw (getkword "\nWould you like to do it again [Yes,No] :"))

When the kw response of yes is given it would jump to the beginning

will that accomplish such a task

Tharwat
2015-05-15, 08:19 PM
What do you mean by jump in here ?

We have no jumps to do the codes , just if the reply from the user is equal to Yes then it would run to the end of the while function then return to beginning to ask the user again it they want to continue , then if Yes it goes as described earlier here but if the reply was No , it would not continue and would finish safely .

Example for making things much clearer in practical codes .



(defun c:Test (/ p d kw)
(if (setq d (/ (getvar 'VIEWSIZE) 5.)
p (getpoint "\n Specify a point :")
)
(progn
(if (zerop (getvar 'PDMODE))
(setvar 'PDMODE 3)
)
(entmake (list '(0 . "POINT") (cons 10 p)))
(while
(and (not (initget 7 "Yes No"))
(setq kw (getkword
"\nWould you like to draw POINT again [Yes,No] :"
)
)
(eq kw "Yes")
)
(entmake
(list '(0 . "POINT") (cons 10 (setq p (polar p 0. d))))
)
)
)
)
(princ)
)

mbrandt5
2015-05-15, 08:59 PM
Okay now I understand thank you

Tharwat
2015-05-16, 09:18 AM
Okay now I understand thank you

Happy to hear that , you are welcome .