Loops/Break: Difference between revisions

Content added Content deleted
No edit summary
Line 1,159: Line 1,159:


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<lang lisp>(defun get-result (param)
<lang lisp>(defun wait_10 ()
;; According to the emacs lisp maual, the definition of ``catch'' is:
;; (catch 'symbol ..BODY...)
;; it returns either the last expression evaluated in BODY or the value given by ``throw''
(catch 'loop-break
(if (string= param "break")
(throw 'loop-break "breaked")
"pass") ) )</lang>


Example:

<lang lisp>(defun get-result (param)
(catch 'loop-break
(catch 'loop-break
(while 't
(if (string= param "break")
(let ((math (random 19)))
(throw 'loop-break "breaked")
(if (= math 10)
"pass") ) )
(progn (message "Found value: %d" math)

(get-result "break")
(throw 'loop-break math))
(message "current number is: %d" math) ) ) ) ) )
;; returns "breaked"

(get-result "break")
;; returns "pass"


</lang>
(wait_10)</lang>


=={{header|D}}==
=={{header|D}}==