# stepByStep()

## `Range.prototype.stepByStep()`

The `stepByStep()` method performs a callback function with the ability to decide when to move to the next step of the range.

{% code title="range.class.ts" %}

```typescript
public stepByStep(
  callbackFn: (value: Generator<number>, step: Step, max: Max) => void
): this {
  const t = this;
  callbackFn(
    (function* stepByStep(current = t.min - t.step): Generator<number> {
      while (current < t.max) {
        yield (current += t.step);
      }
    })(),
    t.step,
    t.max
  );
  return this;
}
```

{% endcode %}

### Parameters

#### `callbackFn: (value:`[<mark style="color:green;">`Generator`</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)`<`[<mark style="color:green;">`number`</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)`>, step:`[<mark style="color:green;">`Step`</mark>](/draft/range/generic-type-variables.md#range-less-than-min-max-step-greater-than-2)`, max:`[<mark style="color:green;">`Max`</mark>](/draft/range/generic-type-variables.md#range-less-than-min-max-step-greater-than-1)`) => void`

A function that accepts up to three arguments. The `value` is a function generator that allows deciding when to move to the next step, `step` is the step, and `max` is the maximum of a specified `Range` object.

**`value:`**<mark style="color:green;">**`Generator`**</mark>**`<`**[<mark style="color:green;">**`number`**</mark>](https://www.typescriptlang.org/docs/handbook/basic-types.html#number)**`>`** - Function generator allows deciding when to move to the next range step.\
\&#xNAN;**`step:`**[<mark style="color:green;">**`Step`**</mark>](/draft/range/generic-type-variables.md#range-less-than-min-max-step-greater-than-2) - The [`step`](/draft/range/accessors/get-step.md) of a specified [`Range`](/draft/range/overview.md) object.\
\&#xNAN;**`max:`**[<mark style="color:green;">**`Max`**</mark>](/draft/range/generic-type-variables.md#range-less-than-min-max-step-greater-than-1) - The [maximum](/draft/range/properties/max.md) range of a specified [`Range`](/draft/range/overview.md) object.

### Return type

#### [<mark style="color:green;">`this`</mark>](/draft/range/overview.md)

### Returns

The **return value** is the [`Range`](/draft/range/overview.md) instance.

## Example usage

```typescript
// Example usage.
import { Range } from '@angular-package/range';

// Create new instance.
const range = new Range(4, 27, 1.5);

range.stepByStep((value) => {
  // Returns 4
  value.next().value;
  // Returns 5.5
  value.next().value;
  // Returns 7
  value.next().value;
  // Returns 8.5
  value.next().value;
  // Returns 10
  value.next().value;
  // Returns 11.5
  value.next().value;
  // Returns 13
  value.next().value;
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://range.angular-package.dev/draft/range/methods/stepbystep.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
