How can I use the same variable to do multiple functions?

I am wondering how I can use a variable such as "count=1" to do multiple functions in my program in different loops.

`#include <LiquidCrystal.h>

// put your setup code here, to run once:
int count = 0;
int ButtonPin = 11;

int buttonState = 0;

int rs = 4;
int en = 9;
int d4 = 7;
int d5 = 6;
int d6 = 5;
int d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
lcd.begin(16, 2);
pinMode(ButtonPin, INPUT_PULLUP); //when the push button is pressed, it will high on for aorund 20 seconds
}

void loop() {
lcd.setCursor(0, 0);
// put your main code here, to run repeatedly:

int value = analogRead(A0);

if (value < 200) {
count++;
}
buttonState = digitalRead(ButtonPin);

if (buttonState == HIGH) { `

while (count == 1) {

  lcd.clear();

  lcd.setCursor(1, 0);

  lcd.print("Max Score: 5");

  lcd.setCursor(4, 1);

  lcd.print("Score: 1");

  Serial.println("THIS IS ONEEEEEEEEEEEEE");

  delay(10);
}

}

if (buttonState == LOW) { while (count == 1) {

  lcd.clear();

  lcd.setCursor(0, 0);

  lcd.print("Thanks 4 playing");

  delay(2000);

  lcd.setCursor(1, 1);

  lcd.print("Final Score: 1");

  Serial.println("ONNNNNNNEEEEE");

  delay(4000);
}

}
}
'

Hello wow39
It seems to be a school assigment, isn´t it?
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It's barely readable as it stands. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)


the way it's written, you'll be stuck in the while loop if you enter it since count does not change. May be you want an if rather than a while

Please clarify what you mean?

Also... is it an infinite loop?

i mean how can i use the my count values to be in different loops with one variable?

and i dont htink it would be infinite since i plan to add more counts in to change the value, therefore the change the display. This also goes for the buttonlow value as well.

Your request doesn’t make any sense in and of itself…
You may be thinking of global variables, or passed parameters… or something.

Either way, you should read up on the ‘scope’ of variables - that may get you halfway to wherever you’re going.

well, at the moment it's an infinite loop just printing over and over again the same thing every 10ms... this has limited value...

To make it a non infinite loop you'll have to modify count somewhere within the while.
Once you get there post your code, not snippets (Snippets R Us!) and we can discuss what you have in mind