Why is the program ignoring my second for- loop?

Please help me, im a beginner in Processing.
Before I’ll tell my problem I’ll twll you about the programm so u wont get confused.
I want to create 2 arrows (left and right) they need to be next to eachother. I need 4 rows of these.
I made te arrows with a picture and tried to make them using a for loop( so I don’t have to create every single arrow and place it). The first for loop is a sucess but the second one doesn’t want to listen.
Is there a way to fix this or did I go the wrong eay and need to programm it in a different way?
Here’s the code:

<
PImage pfeilRechts;
PImage pfeilLinks;
int pU= 35;
int p1Y= 230;
int p1Y2= 340;
int p1X= 45;
int p1X2= 80;
int arrow;
void setup() {
size(800, 600);
arrowLeft= loadImage(“PfeilLinks.png”);
arrowRight= loadImage(“PfeilRechts.png”);
}
void draw() {
createArrowFirstRow();
createArrowSecondRow();
}
}
void createArrowFirstRow(){
for(int i=0; arrow<5; arrow++){//Arrow ++ damit so it won’r repeat again
imageMode(CENTER);
image(arrowLeft, p1X, p1Y, pU, pU);
p1X+=75;
image(arrowRight, p1X2,p1Y, pU, pU);
p1X2+=75;
}
}
void createArrowSecondRow();(){
for(int i=0; arrow <5; arrow++){//Arrow ++ damit so it won’t repeat again
imageMode(CENTER);
image(arrowLeft, p1X, p1Y2, pU, pU);
p1X+=75;
image(arrowRight, p1X2,p1Y, pU, pU);
p1X2+=75;
}
}
<

normally we use three times the same variable:

for(int arrow=0; arrow<5; arrow++){

since arrow is 5 (after the 1st for loop) in your approach, in the second for-loop the condition arrow <5 is not met so the 2nd for-loop doesn’t run

thank you for your reply. I’ve tried using three times the same variable but then thr pictures wouldn’t stop being produced. How do I code the for loop to work?

You can say noLoop(); in draw() or reset the variables that you increase (reset them at the start of draw ())

Use background at start of draw

1 Like