[Swift-devel] how to increment int?

Ben Clifford benc at hawaga.org.uk
Tue Dec 18 06:16:27 CST 2007



> In the swift code loop below I need to increment the
> start_job variable by 1, however I get the error that
> start_job is already assigned, how should I do it? 

> while( start_job < 10000998){

Don't use while - it shouldn't even be in the language, in my opinion, 
given that I've never seen a successful use of it.

Here are two ways of saying what I think you want:

THere's an 'iterate' statement that will give you a counter for each loop.

Section 2.6.4 in here: 
http://www.ci.uchicago.edu/swift/guides/userguide.php#id2663424

something like

iterate i {
    int job_number = i + 10000000;
    [...]
} until(job_number >= 1000098)


You could also express it as this, which perhaps better expresses the 
parallelism (though I think both the iterate use above and the foreach use 
below will behave about the same).

foreach job_number in [1000000:10000098] {
   [....]
}


-- 





More information about the Swift-devel mailing list