# Loop through a sequence

**URL:** <https://discourse.processing.org/t/loop-through-a-sequence/26242>\
**Category:** Coding Questions\
**Created:** [December 14, 2020, 5:17pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242 "2020-12-14T17:17:22Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [December 14, 2020, 5:17pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/1 "2020-12-14T17:17:22Z")

</div>

How do I loop through this sequence separated by commas so I can determine the minimum value?

x = (min(splitFloat[0],splitFloat[2],splitFloat[4]);

Thank you.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 14, 2020, 7:09pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/2 "2020-12-14T19:09:07Z")

</div>

What do you mean by this sequence?

```auto
float[] splitFloat = {0.1, 0.2, 0.3, 0.4, 0.5};
float x = min(splitFloat[0],splitFloat[2],splitFloat[4]);
println(x);

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 14, 2020, 7:39pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/3 "2020-12-14T19:39:06Z")

</div>

I guess now I know what you are asking. It is how the min() function is done internally, isn’t it.

```auto
float[] splitFloat = {0.3, 0.2, 0.5, 0.4, 0.1};
float min = splitFloat[0];

void setup() {
  for (int i = 1; i < splitFloat.length; i++) {
    if (splitFloat[i] < min) {
      min = splitFloat[i];
    }
  }
  println(min);
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 14, 2020, 7:54pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/4 "2020-12-14T19:54:37Z")

</div>

Oops, It’s P5.js

```auto
var splitFloat = [0.3, 0.2, 0.5, 0.4, 0.1];

let min = splitFloat[0];

function setup() {
  for (let i = 1; i < splitFloat.length; i++) {
    if (splitFloat[i] < min) {
      min = splitFloat[i];
    }
  }
  print(min);
}

```

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [December 15, 2020, 6:04pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/5 "2020-12-15T18:04:26Z")

</div>

> [@noel](#):
>
> `let min = splitFloat[0];`

Thank you very much Mr. Noel, I’ve applied the code you gave me and it worked perfectly. You are such a gem, you open me up to so many possibilities. I truly appreciate, God bless you.

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [January 12, 2021, 2:17pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/6 "2021-01-12T14:17:56Z")

</div>

Hi Noel, how are you?..is it possible to use ‘‘if statements’’ to draw different instance of ellipses assuming you have to loop through these numbers ; 4,9,7,15,11,23  
e.g  
if (x1\>x2) {  
ellipse(((i\*50,(i+1)_50 2, 2);  
}  
else if (x1==x2) {  
ellipse(((i_50,(i+1)_50 4, 4);  
}  
else(x1\<x2) {  
ellipse(((i_50,(i+1)\*50 7, 7);  
}

Please see how you can make this work, I’ve tried and it’s not working for me.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 2:54pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/7 "2021-01-12T14:54:13Z")

</div>

> [@Chigoz](#):
>
> you have to loop through these numbers ; 4,9,7,15,11,23

Hi @Chigoz  
These numbers are related to which variable? (x1, x2 or i)?

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [January 12, 2021, 2:56pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/8 "2021-01-12T14:56:52Z")

</div>

ok, it should be i, i+1

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [January 12, 2021, 3:03pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/9 "2021-01-12T15:03:45Z")

</div>

You can create different data sets that reflects the different conditions

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [January 12, 2021, 3:13pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/10 "2021-01-12T15:13:18Z")

</div>

I think two numbers are ok i,e condition (1) 9 ,7 , condition(2) 6,6 and condition(3) 7,9

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [January 12, 2021, 3:16pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/11 "2021-01-12T15:16:16Z")

</div>

I can’t see the rest of the code, so I used some random values. It’s weird of course, but it shows how to loop through the numbers.

```auto
var number = [4,9,7,15,11,23];

let x1, x2, i = 0;

function setup() {
  createCanvas(500, 500);
}

function draw() {
  x1 = random(width);
  x2 = random(width);
  if (x1 > x2) {
    fill(255, 0, 0);
    ellipse(number[i]*x1, (number[i]+1)*x2, 30, 30);
  } else if (x1 == x2) {
    fill(0, 0, 255);
    ellipse(number[i]*x1, (number[i]+1)*x2, 10, 10);
  }
   else if(x1 < x2) {
     fill(0, 255, 0);
    ellipse(number[i]*x1, (number[i]+1)*x2, 20, 20);
  }
  i++;
  if(i > number.length-1) i = 0;
}

```

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [January 12, 2021, 3:20pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/12 "2021-01-12T15:20:50Z")

</div>

Thanks, let me apply them.

---

<div class="post-metadata">

**Author:** ![Chigoz](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@Chigoz](https://discourse.processing.org/u/Chigoz)\
**Post date:** [January 26, 2021, 10:23pm UTC](https://discourse.processing.org/t/loop-through-a-sequence/26242/14 "2021-01-26T22:23:59Z")

</div>

Hello Noel, how are you?, this is what I’ve done so far on my project. I’ll still add to it as I get more ideas. Tell me what you think. Thank you very much for your help.

[https://dl.dropboxusercontent.com/s/7roczkhdht0dojx/Graph%20Plotting%20demonstration%20for%20Noel.mp4?dl=0](https://dl.dropboxusercontent.com/s/7roczkhdht0dojx/Graph%20Plotting%20demonstration%20for%20Noel.mp4?dl=0)
