# Series from For loop (is there a repository for Integer Sequences?)

**URL:** <https://discourse.processing.org/t/series-from-for-loop-is-there-a-repository-for-integer-sequences/44970>\
**Category:** Beginners\
**Created:** [August 21, 2024, 6:44am UTC](https://discourse.processing.org/t/series-from-for-loop-is-there-a-repository-for-integer-sequences/44970 "2024-08-21T06:44:37Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 21, 2024, 3:20pm UTC](https://discourse.processing.org/t/series-from-for-loop-is-there-a-repository-for-integer-sequences/44970/6 "2024-08-21T15:20:17Z")

</div>

We could also create separate functions which would create the sequence array of the desired type for us.

Here’s your 1st example as a function named **seqIntsRepeatedNTimesEach(n, lo, hi)**:

```auto
int[] seq4_1_20, seqNeg4_1_20, seq1_10_Neg10;

void setup() {
  seq4_1_20 = seqIntsRepeatedNTimesEach(4, 20);
  seqNeg4_1_20 = seqIntsRepeatedNTimesEach(4, -20);
  seq1_10_Neg10 = seqIntsRepeatedNTimesEach(-1, 10, -10);

  println(str(seq4_1_20));
  println();
  println(str(seqNeg4_1_20));
  println();
  println(str(seq1_10_Neg10));

  exit();
}

static final int[] seqIntsRepeatedNTimesEach(final int n, final int hi) {
  return seqIntsRepeatedNTimesEach(n, hi >= 0 ? 1 : -1, hi);
}

static final int[] seqIntsRepeatedNTimesEach(
  final int n, final int lo, final int hi)
{
  final int
    nn = Math.abs(n), 
    len = (Math.abs(hi - lo) + 1) * nn, 
    dir = hi >= lo ? 1 : -1, 
    seq[] = new int[len];

  for (int i = 0; i < len; ++i) seq[i] = i / nn * dir + lo;

  return seq;
}

```

1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15 15 15 16 16 16 16 17 17 17 17 18 18 18 18 19 19 19 19 20 20 20 20 -1 -1 -1 -1 -2 -2 -2 -2 -3 -3 -3 -3 -4 -4 -4 -4 -5 -5 -5 -5 -6 -6 -6 -6 -7 -7 -7 -7 -8 -8 -8 -8 -9 -9 -9 -9 -10 -10 -10 -10 -11 -11 -11 -11 -12 -12 -12 -12 -13 -13 -13 -13 -14 -14 -14 -14 -15 -15 -15 -15 -16 -16 -16 -16 -17 -17 -17 -17 -18 -18 -18 -18 -19 -19 -19 -19 -20 -20 -20 -20 10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10

---

_[View the full topic](https://discourse.processing.org/t/series-from-for-loop-is-there-a-repository-for-integer-sequences/44970)._
