www.digitalmars.com         C & C++   DMDScript  

c++.beta - for loop increment expression and if statement

reply Richard Grant <fractal clark.net> writes:
Not sure if this should be legal or not.. standard says "most" statements are
expressions.

int main() {

for (int i=0; i < 10; i++, if (i == 5) break);
// Error: expression expected
}

A work around:

for (int i=0; i < 10; i++, (i == 5) ? i = 10 : 0);

Richard
Feb 13 2003
parent "Walter" <walter digitalmars.com> writes:
"Richard Grant" <fractal clark.net> wrote in message
news:b2h7fk$2rj8$1 digitaldaemon.com...
 Not sure if this should be legal or not.. standard says "most" statements
are
 expressions.

 int main() {

 for (int i=0; i < 10; i++, if (i == 5) break);
 // Error: expression expected
 }
I don't think it's legal.
Feb 13 2003