# Can I use map () in a loop?

**URL:** <https://discourse.processing.org/t/can-i-use-map-in-a-loop/37511>\
**Category:** Coding Questions\
**Created:** [June 12, 2022, 8:27pm UTC](https://discourse.processing.org/t/can-i-use-map-in-a-loop/37511 "2022-06-12T20:27:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvb](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@mvb](https://discourse.processing.org/u/mvb)\
**Post date:** [June 12, 2022, 8:27pm UTC](https://discourse.processing.org/t/can-i-use-map-in-a-loop/37511/1 "2022-06-12T20:27:43Z")

</div>

I have a piece of code and I want to use the map() in order to have the last column of the array with values between 5 and 60. 5 will equal to the minimum value and 60 to the maximum, and the numbers in the middle they will follow a linear relationship with the previous rule.  
My question is, how can I transform all the numbers of the last column of the array using map()? I was thinking in using a loop, first I have found the maximum and minimum values of the column and now I don’t know how to transform the rest. I use the float a later.

```auto
int max = cities[0][2];
int min = cities[0][2];

for (int j=1; j<cities.length; j++){
 if (cities[j][2] < min){
   min=cities[j][2];
  }
  if(cities[j][2] > max){
   max=cities[j][2];
  }
  
  float a= map(j, min, max, 5, 60);
  ...
}

```

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [June 12, 2022, 11:26pm UTC](https://discourse.processing.org/t/can-i-use-map-in-a-loop/37511/2 "2022-06-12T23:26:37Z")

</div>

> [@mvb](#):
>
> … can I create a loop and put the map() in it for all the numbers?

Do you mean something like this?

```auto
void setup() {
  size(200, 200);
}

void draw() {
  noFill();
  int[] vals = {1, 77, 100, 20, 56, 32, 88};
  for (int v: vals) {
    circle(width / 2, height / 2, map(v, 1, 100, 5, 60));
  }
}

```

Resulting image:

 ![circles](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/6/c669cef743ea2a5df49630c08523b1a0ea4a6f1e.png)

_Edited to correct a typographical error._
