I have added a new  of loops:

for 
  var i =1; 
  while i <= 10; 
  next ++i; 
do
  println$ i
done

This is similar to a standard C loop. The initialiser can be any statement
(but only one).  The loop executes whilst the while condition holds,
not at all if it doesn't hold initially. The next statement is done
after each iteration before retesting the while condition.

This is NOT the same as the existing Felix for loops, 
because the Felix loops guarantee the terminating
value of the control variable does not exceed the final
value. That makes these loops expensive compared
to the C loop, but it is essential if, for example,
incrementing a variable would go past the legal end of
the type (either it would crash or wrap around and prevent
termination). 

But the C form is more general and can be constructed to
handle either 0 iterations or a full range of the type
for both signed and unsigned types, as well has
looping through lists, STL data structure, etc.

This loop supports labelled break, continue, and redo
like other loops.

I also put in:

for 
  var j =1; 
  until j > 10; 
  next ++j; 
do

which is the same except the condition is negated.

in addition I have added some COBOL. Well, you can now write
a compound statement with one statement in it:

for var i in set perform println$ i;

instead of

for var i in set do println$ i; done

Just a reminder the other compound is begin .. end,
similar to do .. done except it creates a procedure closure
which is invoked.  This restricts declared variable to the
scope of the body, but it also prevent jumping into the body
and changes the meaning of "return" to return from the closure
not the procedure containing the loop. You can use

        return from procname;

to ensure you're returning from the enclosing procedure, however.
[but you cannot do that with functions!]

Finally: I first used the C like syntax

        for ( var i = 1; i < 10; ++i; ) do ... done

however the ":" at the end of the ++i is mandatory because the
next operation has to be a statement not an expression.
So it seemed better you use a more verbose syntax.

I could change his (but the trailing ";" after the ++i can't be
eliminated)

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to