How to resolve the algorithm Loops/For with a specified step step by step in the Haxe programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/For with a specified step step by step in the Haxe programming language

Table of Contents

Problem Statement

Demonstrate a   for-loop   where the step-value is greater than one.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/For with a specified step step by step in the Haxe programming language

Source code in the haxe programming language

class Step {
  var end:Int;
  var step:Int;
  var index:Int;

  public inline function new(start:Int, end:Int, step:Int) {
    this.index = start;
    this.end = end;
    this.step = step;
  }

  public inline function hasNext() return step > 0 ? end >= index : index >= end;
  public inline function next() return (index += step) - step;
}

class Main {
  static function main() {
    for (i in new Step(2, 8, 2)) {
      Sys.print('$i ');
    }
    Sys.println('WHOM do we appreciate? GRAMMAR! GRAMMAR! GRAMMAR!');
  }
}


  

You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Picat programming language
You may also check:How to resolve the algorithm Ludic numbers step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Set step by step in the Ring programming language
You may also check:How to resolve the algorithm Mertens function step by step in the CLU programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Maple programming language