[Gmsh] "For" loop with a variable incrementation step
Christophe Geuzaine
cgeuzaine at ulg.ac.be
Tue Oct 20 22:11:36 CEST 2009
Lucas Blattner Martinho wrote:
> Dear Gmsh developers,
>
>
> I am trying to use Gmsh's "For" loop with a variable incrementation
> step, however I am not obtaining the expected results.
>
> For example, I expected the following Gmsh commands
>
> step = 1.0;
> For k In {0:100:step}
> Printf("step = %f k = %f", step, k ) >> "test.txt";
> step = step +1;
> EndFor
>
>
> would produce an output file called "test.txt" containing the following
> data:
>
> step = 1.000000 k = 0.000000
> step = 2.000000 k = 2.000000
> step = 3.000000 k = 5.000000
> .
> .
> .
> and so on.
>
>
> However, the previous commands result in the following output file:
>
> step = 1.000000 k = 0.000000
> step = 2.000000 k = 1.000000
> step = 3.000000 k = 2.000000
> step = 4.000000 k = 3.000000
> step = 5.000000 k = 4.000000
> .
> .
> .
> and so on.
>
>
> It seems that incrementation of the "step" variable inside the loop does
> not result in a variable update of "k", which keeps growing with unit steps.
>
> I found this strange behaviour while trying to emulate a "While" loop ,
> which doesn't appear to be promptly available in Gmsh (by setting a
> "step" variable bigger than the "for" loop's range, when some break
> condition is satisfied ).
>
>
> Am I missing something and these are in fact the expected behaviours, or
> would this be a bug of some sort?
Indeed, it's a limitation of our implementation: we don't reevaluate the
arguments of the For after each iteration...
> Is there a better way to work these issues around (emulating a "While"
> loop) ?
>
Not that can I directly think of. I am adding this issue to our TODO list.
Thanks for the feedback,
Christophe
>
>
> yours faithfully,
> Lucas Blattner Martinho
> **
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gmsh mailing list
> gmsh at geuz.org
> http://www.geuz.org/mailman/listinfo/gmsh
--
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine