package jetbrains.mps.baseLanguage.collections.samples.sequence_queries;

/*Generated by MPS */

import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.baseLanguage.closures.runtime.YieldingIterator;
import jetbrains.mps.internal.collections.runtime.StopIteratingException;

/*package*/ class Main_forEach_operation {
  /*package*/ Main_forEach_operation() {
  }
  /*package*/ static void main(String[] args) {
    Iterable<Integer> nums = Sequence.fromClosure(() -> {
      return (Iterable<Integer>) () -> {
        return new YieldingIterator<Integer>() {
          private int __CP__ = 0;
          protected boolean moveToNext() {
__loop__:
            do {
__switch__:
              switch (this.__CP__) {
                case -1:
                  assert false : "Internal error";
                  return false;
                case 4:
                  if (true) {
                    this.__CP__ = 5;
                    break;
                  }
                  this.__CP__ = 1;
                  break;
                case 6:
                  this.__CP__ = 7;
                  this.yield(_3_num);
                  return true;
                case 0:
                  this._3_num = 0;
                  this.__CP__ = 4;
                  break;
                case 5:
                  this.__CP__ = 6;
                  break;
                case 7:
                  _3_num++;
                  this.__CP__ = 4;
                  break;
                default:
                  break __loop__;
              }
            } while (true);
            return false;
          }
          private int _3_num;
        };
      };
    });
    System.out.println("from infinite sequence take first 10 numbers,");
    System.out.println("ignore odd numbers,");
    System.out.println("print even numbers");
    Sequence.fromIterable(nums).visitAll((n) -> {
__skip__:
      do {
        if (n >= 10) {
          throw new StopIteratingException();
        }
        if (n % 2 != 0) {
          break __skip__;
        }
        System.out.println(n);
      } while (false);
    });
  }
}
