[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: single line Mata do-while cycle

From   "Newson, Roger B" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: single line Mata do-while cycle
Date   Tue, 22 Sep 2009 18:39:56 +0100

I think the problem you are having is that Mata is a compilable language, and not an interpretable language like Stata. To make loops work in Mata, you have to put them inside a function (which will be compiled after it is written), and then call the function.

I hope this helps.

Best wishes


Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected] 
Web page:
Departmental Web page:

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Stas Kolenikov
Sent: 22 September 2009 18:32
To: [email protected]
Subject: st: single line Mata do-while cycle

I was expecting this snippet of code to work:

do k=k+1 while (k<10)


: k=0

: do k=k+1 while (k<10)
'while' found where almost anything else expected

Breaking this into multiple lines does not help:

: do k=k+1
nothing found where 'while' expected

However, this one works:

do k=k+1; while (k<10)

Is that the case of "significant" semicolons per [M-2] semicolons? I
know that I sometimes need to use semicolons after -if- to indicate
absence of -else- statement in crooked branching code.

Stas Kolenikov, also found at
Small print: I use this email account for mailing lists only.
*   For searches and help try:

*   For searches and help try:

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