txt: ## label.md
  class Label
  
  Tagged location in the source code
  
  ```raku
  class Label {}
  ```
  
  Labels are used in Raku to tag loops so that you can specify the specific one you want to jump to with [statements such as `last`](/language/control#LABELs). You can use it to jump out of loops and get to outer ones, instead of just exiting the current loop or going to the previous statement.
  
  ```raku
  USERS:          # the label
  for @users -> $u {
      for $u.pets -> $pet {
          # usage of a label
          next USERS if $pet.barks;
      }
      say "None of {$u}'s pets barks";
  }
  say USERS.^name;        # OUTPUT: «Label␤»
  
  ```
  
  Those labels are objects of type `Label`, as shown in the last statement. Labels can be used in any loop construct, as long as they appear right before the loop statement.
  
  ```raku
  my $x = 0;
  my $y = 0;
  my $t = '';
  A: while $x++ < 2 {
      $t ~= "A$x";
      B: while $y++ < 2 {
          $t ~= "B$y";
          redo A if $y++ == 1;
          last A
      }
  }
  say $t; # OUTPUT: «A1B1A1A2␤»
  
  ```
  
  Putting them on the line before the loop or the same line is optional. `Label`s must follow the syntax of [ordinary identifiers](/language/syntax#Ordinary_identifiers), although traditionally we will use the latin alphabet in uppercase so that they stand out in the source. You can use, however, other alphabets like here:
  
  ```raku
  駱駝道: while True {
    say 駱駝道.name;
    last 駱駝道;
  }  # OUTPUT: «駱駝道␤»
  ```
  
  # [Methods](#class_Label "go to top of document")[§](#Methods "direct link")
  
  ## [method name](#class_Label "go to top of document")[§](#method_name "direct link")
  
  Not terribly useful, returns the name of the defined label:
  
  ```raku
  A: while True {
    say A.name; # OUTPUT: «A␤»
    last A;
  }
  ```
  
  ## [method file](#class_Label "go to top of document")[§](#method_file "direct link")
  
  Returns the file the label is defined in.
  
  ## [method line](#class_Label "go to top of document")[§](#method_line "direct link")
  
  Returns the line where the label has been defined.
  
  ## [method Str](#class_Label "go to top of document")[§](#method_Str "direct link")
  
  Converts to a string including the name, file and line it's been defined in.
  
  ## [method next](#class_Label "go to top of document")[§](#method_next "direct link")
  
  ```raku
  method next(Label:)
  ```
  
  Begin the next iteration of the loop associated with the label.
  
  ```raku
  MY-LABEL:
  for 1..10 {
      next MY-LABEL if $_ < 5;
      print "$_ ";
  }
  
  # OUTPUT: «5 6 7 8 9 10 »
  ```
  
  ## [method redo](#class_Label "go to top of document")[§](#method_redo "direct link")
  
  ```raku
  method redo(Label:)
  ```
  
  Repeat the same iteration of the loop associated with the label.
  
  ```raku
  my $has-repeated = False;
  
  MY-LABEL:
  for 1..10 {
      print "$_ ";
      if $_ == 5 {
          LEAVE $has-repeated = True;
          redo MY-LABEL unless $has-repeated;
      }
  }
  
  # OUTPUT: «1 2 3 4 5 5 6 7 8 9 10 »
  ```
  
  ## [method last](#class_Label "go to top of document")[§](#method_last "direct link")
  
  ```raku
  method last(Label:)
  ```
  
  Terminate the execution of the loop associated with the label.
  
  ```raku
  MY-LABEL:
  for 1..10 {
      last MY-LABEL if $_ > 5;
      print "$_ ";
  }
  
  # OUTPUT: «1 2 3 4 5 »
  ```
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `Label`
  
  
  
  raku-type-graph
  
  
  
  Label
  Label
  
  
  Any
  Any
  
  
  Label->Any
  
  
  
  Mu
  Mu
  
  
  Any->Mu
  
  [Expand chart above](/assets/typegraphs/Label.svg)
  