Statalist


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

Re: st: re: WHILE command


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: re: WHILE command
Date   Tue, 18 Mar 2008 11:24:15 -0400

Agree that -while- is dispensible, but there are situations
(such as the one described here by Kit) where it makes for
much more readable code. Looking at

 while `grad'>=`eps' {
         ...
 }

one knows right away what the loop is about. So let's not get
rid of it just yet.


Jeph



Kit Baum wrote:
Nick W said

How does one do this in cases where one cannot calculate, in advance,
the number of repetitions needed, or the list of items to be acted upon?

As Nick C has pointed out, nothing stops you from using a forvalues loop over a large number of values and testing within the loop to determine whether some condition is now satisfied (e.g., if the norm of the gradient is now less than epsilon), and using

continue, break

to terminate the loop at that point.


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


*
* 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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index