class TestCase::Statement::For {
  use TestCase::Minimal;

  static method omit_init_inc : int () {
    
    my $i = 0;
    my $total = 0;
    for (; $i < 11;) {
      $total += $i;
      $i++;
    }
    
    unless ($total == 55) {
      return 0;
    }
    
    return 1;
  }
  
  static method nested_last_with_switch : int () {
    my $num1 = 0;
    for (my $i = 0; 1;$i++) {
      
      if ($i == 2) {
        $num1++;
        last;
      }
      
      switch ($i) {
        case 1: {
          break;
        }
        default: {
          $num1++;
        }
      }
      $num1++;
    }
    
    unless ($num1 == 4) {
      return 0;
    }
    
    return 1;
    
  }

  static method nested_next : int () {
    
    my $total1 = 0;
    my $total2 = 0;
    for (my $i = 0; $i < 3; $i++) {
      if ($i == 2) {
        if (0) {
          next;
        }
        next;
        if (0) {
          next;
        }
      }
      for (my $j = 0; $j < 3;$j++) {
        if ($j == 2) {
          next;
        }
        $total2++;
      }
      $total1++;
    }
    
    unless ($total1 == 2) {
      return 0;
    }
    
    unless ($total2 == 4) {
      return 0;
    }
    
    return 1;
  }

  static method nested_last : int () {
    my $ret = 0;
    for (my $i = 0; 1;$i++) {
      if ($i == 2) {
        if (0) {
          last;
        }
        $ret = 1;
        last;
        
        if (0) {
          last;
        }
      }
      for (my $j=0; 1;$j++) {
        if ($j == 2) {
          last;
        }
      }
    }
    
    unless ($ret) {
      return 0;
    }
    
    return 1;
  }
  
  # For
  static method basic : int () {
    
    {
      my $total = 0;
      for (my $i = 1; $i <= 3; $i++) {
        $total = $total + $i;
      }
      
      unless ($total == 6) {
        return 0;
      }
    }
    
    {
      my $total = 0;
      for (my $i = 0; $i < 10; $i++) {
        if ($i == 5) {
          last;
        }
        $total = $total + $i;
      }
      
      unless ($total == 10) {
        return 0;
      }
    }
    
    {
      my $total = 0;
      for (my $i = 0; $i < 10; $i++) {
        if ($i == 5) {
          next;
        }
        $total = $total + $i;
      }
      
      unless ($total == 40) {
        return 0;
      }
    }

    # Check also object count
    {
      my $total = 0;
      for (my $i = 0; $i < 10; $i++) {
        my $minimal = TestCase::Minimal->new();
        if ($i == 5) {
          last;
        }
        $total = $total + $i;
      }
      
      unless ($total == 10) {
        return 0;
      }
    }
    
    # Check also object count
    {
      my $total = 0;
      for (my $i = 0; $i < 10; $i++) {
        my $minimal = TestCase::Minimal->new();
        if ($i == 5) {
          next;
        }
        $total = $total + $i;
      }
      
      unless ($total == 40) {
        return 0;
      }
    }
    
    # No condition operand
    {
      my $enter_block = 0;
      
      for (;;) {
        $enter_block = 1;
        last;
      }
      
      unless ($enter_block) {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method next_statement : int () {
    my $total = 0;
    for (my $i = 0; $i < 5; $i++) {
      if ($i == 1) {
        next;
      }
      if ($i == 3) {
        next;
      }
      $total += $i;
    }
    
    unless ($total == 6) {
      return 0;
    }
    
    return 1;
  }
  
  static method condition_my : int () {
    
    my $num = 5;
    for (;my $num = 3;) {
      if ($num == 3) {
        last;
      }
      else {
        return 0;
      }
    }
    
    return 1;
  }

  static method foreach : int () {
    {
      my $array = [1, 2, 3];
      my $total = 0;
      for my $element (@$array) {
        $total += $element;
      }
      
      unless ($total == 6) {
        return 0;
      }
    }
    
    {
      my $array = [1, 2, 3];
      my $total = 0;
      for my $element (@{$array}) {
        $total += $element;
      }
      
      unless ($total == 6) {
        return 0;
      }
    }
    
    # Empty Block is OK
    {
      my $array = [1, 2, 3];
      for my $element (@{$array}) {
      }
    }
    
    # last
    {
      my $array = [1, 2, 3];
      my $total = 0;
      for my $element (@$array) {
        if ($element == 3) {
          last;
        }
        $total += $element;
      }
      
      unless ($total == 3) {
        return 0;
      }
    }

    # next
    {
      my $array = [1, 2, 3];
      my $total = 0;
      for my $element (@$array) {
        if ($element == 2) {
          next;
        }
        $total += $element;
      }
      
      unless ($total == 4) {
        return 0;
      }
    }
    
    return 1;
  }
}
