Swift - Statement Labeled Statement

Introduction

To break from the outer loop, add a label prior to the outer While loop:

Demo

var i = 0
outerLoop:  while i<3 {
    i = i + 1//  ww  w .  j a  v a  2s.c  om
    var j = 0
    while j<3 {
       j = j + 1
       print("(\(i),\(j))")
       break outerLoop  //exit the inner While loop
    }
}

Result

You can specify which While loop you are trying to break out of by specifying the label outerLoop.

You can use the labeled statement with the continue keyword:

Demo

var i = 0
outerLoop: while i<3 {
   i++//from w  ww  .ja  v a 2 s.  co  m
   var j = 0
   while j<3 {
      j++
      print("(\(i),\(j))")
       continue outerLoop  //go to the next iteration of the
                           // outer While loop
   }
}