Another loop in void loop function?

Hello, i need your help.

i am trying to make a code that sets up a value, reads sensor and then it does something if sensor value is greater than the value.
i am stuck at setting up value. I want minimum value to be 960. i have set this up. But how to increase and decrease value? i've planned to use OneWireKeypad.getkey and in case '1' it would increase value and in case '2' it would decrease value. i've planned to use maxvalue++ and maxvalue --.

My question is where it should be? i've planned to put it in void loop but then i would have to set up the value all the time, if i am right.

And another question, if i press '1', would it increase my value only for 1? i mean do i have to press it all the time or it reads multiple presses if i hold the '1' key pressed?

include <OnewireKeypad.h>

#include <LiquidCrystal.h>

#define Rows 4
#define Cols 4
#define Pin A0
#define Col_Res 4700
#define Row_Res 1000

char KEYS[]= {
  '1','2','3','A',
  '4','5','6','B',
  '7','8','9','C',
  '*','0','#','D'
};

OnewireKeypad <Print, 16> KeyPad(Serial, KEYS, Rows, Cols, Pin, Col_Res, Row_Res );


int sensor1 = 2; // pin za senzor 1
int sensorValue1 = 0; 
int mappedValue1;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12, 13);
#define RELAY1 3 
int maxvalue = 960;
void setup(){
  lcd.begin(16, 2);
  Serial.begin(9600);  
  lcd.print("odredite");
}
void loop(){
sensorValue1 = analogRead(sensor1); 
delay(1000); 
lcd.print("sensor 1 = " ); 
lcd.println();
lcd.println(sensorValue1); 
lcd.println();
if (sensorValue1 < maxvalue ) 
{
digitalWrite(RELAY1, LOW); 
}
if (sensorValue1 > maxvalue) 
{
digitalWrite(RELAY1, HIGH); 
}
}

i am trying to make a code that sets up a value, reads sensor and then it does something if sensor value is greater than the value.

Is "the value" stored in the variable named maxvalue?

My question is where it should be? i've planned to put it in void loop

That would be the correct place.

but then i would have to set up the value all the time, if i am right.

If, by "all the time", you mean "every time the Arduino resets", that is correct.

Of course, you could store the value in EEPROM and read the stored value, in setup(), so that you wouldn't need to do that.

And another question, if i press '1', would it increase my value only for 1? i mean do i have to press it all the time or it reads multiple presses if i hold the '1' key pressed?

That depends on how you write the code.

Is "the value" stored in the variable named maxvalue?

Yeah, it is.

Don't think of the problem as a loop within loop(). If the program gets more complex that will just result in spaghetti that is impossible to maintain. Instead break the problem into different functions that are each called from loop(). And ensure that loop() can repeat as often as possible - hundreds or thousands of times per second.

You may get some ideas from planning and implementing a program.

...R