# Loop after loop in setup

If i want to use a specific loop for two different functions inside the draw what am i suppose to do??
For example if i want to use this :

for (int i=0; i<table.getRowCount(); i++) {

for two different function inside setup, must i write it like this?

``````void setup() {
for (int i=0; i<table.getRowCount(); i++) {
float y=table.getFloat(i, "y");
table.sortReverse("y")
float max_y= table.getFloat(0, "y")
float y2=max_y/2;
}
for (int i=0; i<table.getRowCount(); i++) {
float y=table.getFloat(i, "y")
if (y>y2) {
println("Everything is ok");
}
}
}
``````

From what I understand in your question, it depends on what you need. For loops just keep repeating whatever is within it until a condition is met.

I pretty sure for your scenario you would need 2 for loops, because you would need to sort an whole array before checking it.

However you should be careful when using `max_y` in your second for loop because it is declared in the first one making it inaccessible in the second one. (Unless you have it declared as a global variable elsewhere)

Yeah that’s my problem…I want to use the variable max_y in the second loop to check the other values but i don’t know how to do it…
My problem is very simple: one for loop finds a max value for a table that i load and divide it by 2 and the other same for loop check if there are values above max_y/2.

You can have

``````float max_y= table.getFloat(0, "y");
float y2=max_y/2;
``````

After the first for loop then, because the data will be sorted after it, and you can get the maximum value like you did before.

You mean this:

``````  for (int i=0; i<table.getRowCount(); i++) {
}
float y=table.getFloat(0, "ECG");
table.sortReverse("ECG");
float  max_y= table.getFloat(0, "ECG");

println(max_y);
for (int i=0; i<table.getRowCount(); i++) {
float a=table.getFloat(i, "ECG");
if (a>max_y) {
println("Everything is ok");
}
``````

Yes, except you don’t need `y` anymore. If you want to check if anything is above half of `max_y` it should be `a>max_y/2`