# How to display multiple line using nested loop

**URL:** <https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994>\
**Category:** Beginners\
**Created:** [May 21, 2022, 12:17pm UTC](https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994 "2022-05-21T12:17:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bossinnit](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bossinnit](https://discourse.processing.org/u/Bossinnit)\
**Post date:** [May 21, 2022, 12:17pm UTC](https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994/1 "2022-05-21T12:17:07Z")

</div>

I am trying to draw a lane through the use of nested loop, where i can control the lanes through use of “final int”, I have pretty much tried everything but didn’t result as i would like to be.

```auto

```

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 21, 2022, 12:20pm UTC](https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994/2 "2022-05-21T12:20:28Z")

</div>

The y-coordinate of every line is same regardles of the stage of the loops.  
So only lines with y= height/2/ROAD\_LANE will be drawn.

Does this resolve your issue?

```auto
final int ROAD_LANE = 4;

void setup() {
  size(800,300);
}

void draw() {
 lane(); 
}

//This is my nested loop to draw lanes across the window, but want them to create five of them rather than 1.
 
void lane () {
  stroke(255);
  strokeWeight(3);
  for (int lineX = 0; lineX < width ; lineX += 100) {
    for(int j = 0; j <= height; j+=height/ROAD_LANE) {
      line(lineX, j, lineX+50, j);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Bossinnit](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bossinnit](https://discourse.processing.org/u/Bossinnit)\
**Post date:** [May 21, 2022, 12:30pm UTC](https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994/3 "2022-05-21T12:30:17Z")

</div>

Thank you soo much it certainly does help, but how do i make sure it stays in top of the first half of the screen.

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [May 21, 2022, 12:36pm UTC](https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994/4 "2022-05-21T12:36:31Z")

</div>

> [@Bossinnit](#):
>
> how do i make sure it stays in top of the first half of the screen.

You can change the maximum value of j (y-coordinate to) height/2

```auto
final int ROAD_LANE = 4;

void setup() {
  size(800,300);
}

void draw() {
 lane(); 
}

//This is my nested loop to draw lanes across the window, but want them to create five of them rather than 1.
 
void lane () {
  stroke(255);
  strokeWeight(3);
  for (int lineX = 0; lineX < width ; lineX += 100) {
    for(int j = 0; j <= height/2; j+=height/ROAD_LANE/2) {
      line(lineX, j, lineX+50, j);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Bossinnit](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bossinnit](https://discourse.processing.org/u/Bossinnit)\
**Post date:** [May 21, 2022, 12:39pm UTC](https://discourse.processing.org/t/how-to-display-multiple-line-using-nested-loop/36994/5 "2022-05-21T12:39:16Z")

</div>

Thanks, it worked, really appreciate it.
