mcfly soft
mcfly soft

Reputation: 11655

Howto code a loop with condition in swift

in java I can handle a loop and stop the loop with a condition in 1 line statement.

boolean continue=true;
for (int i=0;i<100 && continue;i++){     // <------ 1 line

Is this also possible in swift and when how ?

Upvotes: 0

Views: 73

Answers (1)

Greg
Greg

Reputation: 25459

Yes you can do the same but in swift continue is a key word so replace it with something different:

    var cont = true
    for var i = 0; i < 100 && cont; i++ {
        println("Value: \(i)")
        if i == 20 {
            cont = false
        }
    }

Upvotes: 2

Related Questions