[Swift-devel] iterate behavior

Jonathan Monette jonmon at utexas.edu
Tue Jul 5 13:53:08 CDT 2011


I do not think it should be like that.  I understand why it would do that.  The java code for that would be:

int i = 0;
do
{
    System.out.println( i );
} while( i++ <= 2 );

but in my opinion the increment of i should be done before the check.  I think stopping at 2 is more intuitive.  In terms of Java:

int i = 0;
do
{
    System.out.println( i );
} while( ++i <= 2 );

On Jul 5, 2011, at 1:50 PM, Ben Clifford wrote:

> 
>> 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.
> 
> -- 
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel




More information about the Swift-devel mailing list