[Swift-devel] iterate behavior

Ben Clifford benc at hawaga.org.uk
Tue Jul 5 13:50:26 CDT 2011


> iterate i {
>   trace(i);
> } until (i > 2);
> 
> I read that "until" as "the iteration body should not be run if i > 2",
> and yet trace goes up to 3. And I'm not sure if that's the right way to
> go.
> 
> Discuss...

closest C-like equivalent (and thus something to emulate) is:

main() {

 int i=0;
 do {
   printf("%d\n",i);
   i++;
 } while(!(i>2));
}

which says:

$ ./a.out 
0
1
2

I suspect when I implemented that I was thinking of the i++ being after 
the condition check, rather than before, but consistency suggests that I 
was wrong.

-- 



More information about the Swift-devel mailing list