The transition statements break and continue in the loop statements in Swift

  • 2020-05-14 05:02:26
  • OfStack

The following example code introduces the transfer statements break and continue in the loop statement Swift, the specific code is as follows:


/**
      A transition statement in a loop statement  break  and  continue
     */
    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
      {
        //  Close the loop and go down 1 loops 
        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)")
//      }
//    }

Related articles: