AbdelRahmen El Lahga wrote:
> Dear all,
> I've written a loop that maximize a given function. In order to
> control convergence i use 3 critereon
> iteration number and 2 scalars for tolerance
> My statement is :
> ...
> while ((critb > eps) || (crita > eps^2) || (iter <= 31)) {
> ....stmts
> iter=iter+1
> }
> I expect that Mata must stop the loop when at least one of
> the three critereon is reached. But the problem is: Mata
> goes untill iteration 112 (for example) and it doesn't stop
> the loop at iteration 31 as expected.
> My output portion is given below:
> End iteration 112.00
> Stepsize: 0.02
> Criterion: 1.35
> Percent variation: 0.00
> ....
> Even when i replace (||) by (|) I get the same results
> any ideas to resolve this problem? Waht is the logic of mata
> to evaluate 3 or more condition in the while loop?
If only one of the three criterion's need to be met,
I think you ought to use the & (or &&) operator instead,
i.e. while ((critb > eps) & (crita > eps^2) & (iter <= 31)) {
....stmts
iter++
}
The while loop continues as long as the expression
is true (non-zero). See -help [M-2] while-
-- Jesper Kjær Hansen
mailto:jkh-stata@msecon.eu
*
* 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/