View previous topic :: View next topic |
Author |
Message |
smjk
Joined: 12 Oct 2007 Posts: 5
|
Posted: Sat Oct 20, 2007 7:59 am Post subject: this minid script code do not work? |
|
|
Code: |
module test;
local ss=0;
local sum=0;
while(ss++<1000000)
sum+=ss;
|
run result:
minid.types.MDCompileException: test.md(3:9): ')' expected; found '++' instead
the code is like c , [while] statement can't continal any expression such as '++' '--' ?? |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sat Oct 20, 2007 8:44 am Post subject: |
|
|
Assignments in MiniD do not have a value like in C or D. ++ and -- are assignments, as they are rewritten as += 1 and -= 1. So no, this code is not legal. You can use a for loop instead:
Code: |
module test;
local ss = 0;
local sum = 0;
// Use <= because in "ss++ < 100000" comparison happens after the ++
for(; ss <= 1000000; ss++)
sum += ss;
|
|
|
Back to top |
|
|
the_darkside_986
Joined: 04 Apr 2008 Posts: 10
|
Posted: Tue Apr 22, 2008 7:00 pm Post subject: |
|
|
Would it be possible to add to the language a return value for assignment for single assignments only that are nested in parentheses? I guess that would add a bit of complexity to the compiler. Or what about a different operator for assignments that should return a value and assignments that do not (and can be multiple) such as ':=' vs. '=' (the latter returning a value)? I guess that would be adding non-C-ish weirdness to the language but it would be neat to have assignments returning values IMO. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Wed Apr 23, 2008 7:33 am Post subject: |
|
|
Assignments returning a value are a possibility, but like you say it'd be restricted to *single* assignments. Personally I think they're awful form and lead to unreadable code (like what the OP posted..) which is why I've disallowed them in the first place. But enough people have moaned about it |
|
Back to top |
|
|
|