Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Use of -exit- within -foreach- or -forvalues-


From   "Ben Jann" <ben.jann@soz.gess.ethz.ch>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Use of -exit- within -foreach- or -forvalues-
Date   Tue, 31 Oct 2006 00:43:09 +0100

Absolutely. However, there are cases in which a program (usually a
subroutine to some other program) should exit without returning error. 
Thanks, ben

Scott wrote:
> If you add a return code, then the code will stop within the loop:
> 
> 
> prog foo3
>    local num 1 2 3
>    foreach n of local num {
> 	if "`n'"=="2" {
>            di "`n' => exit"
>            exit 119
>         }
>    di "`n'"
>    mac shift
>    }
>  di "not to be reached"
> end
> 
> . discard
> 
> . foo3
> 1
> 2 => exit
> r(119);
> 
> 
> prog foo4
>          local list 1 2 3
>          foreach l of local list {
>                  di "`l'"
>                  exit 119
>          }
>          di "howdy"
> end
> 
> 
> . foo4
> 1
> r(119);

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index