0

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 ?

2
  • you can always use an if statement in the for loop to break Commented Mar 5, 2015 at 10:22
  • yes of course I can do, but the question is if this is possible in one line. So the answer is no ? Commented Mar 5, 2015 at 10:24

1 Answer 1

2

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
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that was it. So simple, sorry for asking. I looked at a sample with for i in 0...100 {. Thanks ! I can accept in 7 minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.