# 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:** 11

<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, 6:13pm UTC](https://discourse.processing.org/t/series-from-for-loop-is-there-a-repository-for-integer-sequences/44970/11 "2024-08-21T18:13:31Z")

</div>

Made some smalls changes and now it takes care of the 2nd case of “Simple periodic sequence” as function **periodicIntSeqRepeatedNTimes(n, lo, hi)**:

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

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

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

  exit();
}

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

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

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

  return seq;
}

```

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -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)._
