SoFunction
Updated on 2025-03-10

Transfer statements break and continue in loop statements in Swift

The following is an example code to introduce the transfer statement break and continue in the loop statement in Swift. The specific code is as follows:

/**
      Transfer statements break and continue in loop statements
      */
    let array:Array = [3, 4, 5, 6, 7, 8, 9]
    for k in array
    {
      if k == 5
      {
        print(k)
        break
      }
    }
    print("--------->")
    for k in array
    {
      if k == 5
      {
        // End this cycle and enter the next cycle        continue;
      }
      print("== \(k)")
    }
    print("--------->")
    /**
     'init' is unavailable: use the 'enumerated()' method on the sequence
     */
//    for (index, value) in EnumeratedSequence(array)
//    {
//      if value % 5 == 0
//      {
//        print("==\(index, value)")
//      }
//    }

The above is the transfer statement break and continue in the loop statement in Swift that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!