Help with loop breaks.

So I’m working on a game in which you press a button and a random color is displayed on a multicolor LED. Then using some pots hooked up to analog ins you can control the three colors of another multicolored LED. You try to get it as close as you can to the first LED as fast as you can. I have a LCD that displays Time, and the color variables you are choosing with the pots. Then when you are done you press the button again, and it displays your score for 10 seconds. Now here is where the problem is; I would like for the score to stay until you pressed the button and go back to the void loop waiting for another start press. I thought about using break, but I can’t get it to break the upper loop only if the button is pressed again.
Here is the code:

/*
A game in which you are shown a random color via a multi color LED,
then using the dials, and LCD you try to make your LED as close as you can 
to the color of the other LED. Then your score will be calculated and displayed.
Press the button to start and to stop
*/
#include <LiquidCrystal.h> //Include the LiquidCrystal library
#include <Button.h> //Button library for better button control

//Color pins for the LED
#define RED1 13
#define GREEN1 12
#define BLUE1 11
//Color pins for the 2nd LED
#define RED2 10
#define GREEN2 9
#define BLUE2 8

/* Next line loads the LCD to pins that are displayed
LCD Pin 1(VSS): GND
LCD Pin 2(VDD): +5v
LCD Pin 3(Contrast): 330ohm resistor -> GND
LCD Pin 4(RS): Arduino 31
LCD Pin 5(RW): Arduino 33
LCD Pin 6(Enable): Arduino 35
LCD Pin 7(NoConnection):
LCD Pin 8(NoConnection):
LCD Pin 9(NoConnection):
LCD Pin 10(NoConnection):
LCD Pin 11(Data 4): Arduino 37
LCD Pin 12(Data 5): Arduino 39
LCD Pin 13(Data 6): Arduino 41
LCD Pin 14(Data 7): Arduino 43
LCD Pin 15(Backlight +): Arduino 45
LCD Pin 16(Backlight GND): GND
-----------------------------------------
*/
LiquidCrystal lcd(31, 33, 35, 37, 39, 41, 43);
//Button class declaring button as a PULLUP button on pin 7
Button button = Button(7,PULLUP);

//Variables
int bL = 45;    // pin 45 will control the backlight
// the score varible for calculating the score
int score = 0;
//The Variables applied to the Random LED
int redr = 100;
int grnr = 200;
int blur = 150;
//The variables applied to the Choice LED
int redc = 0;
int grnc = 0;
int bluc = 0;

void setup()
{
  //Setup for the LCD
  pinMode(bL, OUTPUT);
  digitalWrite(bL, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20,4);
  lcd.clear();
 
  //Pinmodes for the Random LED
  pinMode(RED1, OUTPUT); //Pin 1 of LED
  pinMode(GREEN1, OUTPUT); //Pin 2 of LED
  pinMode(BLUE1, OUTPUT); //Pin 3 of LED
  //PinModes for the Choice LED
  pinMode(RED2, OUTPUT); //Pin 1 of LED2
  pinMode(GREEN2, OUTPUT); //Pin 2 of LED2
  pinMode(BLUE2, OUTPUT); //Pin 3 of LED2
  //Button for Start and stop
  pinMode(7, INPUT);
  //Seed Random Nubers for the rest of my program
  randomSeed(analogRead(0));
  
}

void loop()
{
   if(button.isPressed())
  {
    //When button is pressed it starts and
    redr = random(255);
    grnr = random(255);
    blur = random(255);
    //Starts the game function defined at the end. This way the
    //random colors will stay even when the game is cycleing
    startGame();
    
  
  }
  delay(40);
}

void startGame()
{
  for(int time = 1; time <= 19900; time++)
  {
    //redr = 255;
    //blur = 0;
    //grnr = 0;
    analogWrite(RED1,redr);
    analogWrite(GREEN1,grnr);
    analogWrite(BLUE1,blur);
    //Start allowing color changing with the 3 pots
    redc = map(analogRead(1), 0, 1023, 0, 255);
    grnc = map(analogRead(2), 0, 1023, 0, 255);
    bluc = map(analogRead(3), 0, 1023, 0, 255);
    analogWrite(RED2,redc);
    analogWrite(GREEN2,grnc);
    analogWrite(BLUE2,bluc);
    
   //This displays the time, and variables of the colors chosen by
   // the pots on the LCD. You can use the LED and LCD to get as 
   //close as you can to the color
    lcd.clear();
    lcd.setCursor(15,0);
    lcd.print("T:");
    lcd.setCursor(17,0);
    lcd.print(time/17);
    lcd.setCursor(0,0);
    lcd.print("R:");
    lcd.setCursor(2,0);
    lcd.print(redc);
    lcd.setCursor(0,1);
    lcd.print("G:");
    lcd.setCursor(2,1);
    lcd.print(grnc);
    lcd.setCursor(0,2);
    lcd.print("B:");
    lcd.setCursor(2,2);
    lcd.print(bluc);
    delay(50);
    // When you're ready press the button again and it will display your score.
    if(button.isPressed() && button.wasPressed())
    {
      // This is the function for the score.
      score = ((time/17) + abs(redr - redc) + abs(grnr - grnc) + abs(blur - bluc));
      lcd.clear();
      lcd.setCursor(4,1);
      lcd.print("Score: ");
      lcd.setCursor(11,1);
      lcd.print(score);
      delay(10000);
    }
  }
}

I'm sorry I don't know how to use code tags

It is the # in the tool bar above your post box.

You should get rid of all the delays. Think about how YOU would do things, if you were the Arduino.

You have a number of states that the program should be in, and a number of transitions between states.

There is the not-started state, the guessing state, and the done guessing state. There may be others.

There is the transition from not-started to guessing, that occurs when the start button is pressed. There is an action that occurs - lighting one RGB LED with random values.

I’ll leave it you to figure out the other transitions.

During each pass through loop, the program is in only one state. Each of the transition triggers needs to be checked, to see if a transition is needed. If so, make that transition. Otherwise, do whatever is required for the state you are in - displaying the score, reading the pots and adjusting the other RGB led, etc.

So, if the delays are not there then the LCD has a hard time writing everything, and you cant really see anything displayed. I don't know how to get a timer to work without the delay so I can calculate time. I originally had a delay of 1000 so that It would go up every second, but the pot display would only update every second. I need it to update when I change the pots. I'm going to define functions for each state as you said. I think I could figure out how to transition in, but not back out. I will update when I'm done.

Look at the blink without delay example. Think about how YOU would implement a delay, then do something useful during that downtime.

"Delay after the LCD write" : You use the same trick as in the tutorial Blink Led without delay: Note the millis() value, and when ever you reach the "updateLCD" code, you first check if the timer is done and thus if you do an update or skip it.

Update->PaulS: Sometimes I dont see some else is answering as I write my answer ... :-/

I wrote it. I think it will work. I haven’t tested it yet. Here it is if you guys want to look.

A game in which you are shown a random color via a multi color LED,
then using the dials, and LCD you try to make your LED as close as you can 
to the color of the other LED. Then your score will be calculated and displayed.
Press the button to start and to stop

*/
#include <LiquidCrystal.h> //Include the LiquidCrystal library
#include <Button.h> //Button library for better button control

//Color pins for the LED
#define RED1 13
#define GREEN1 12
#define BLUE1 11
//Color pins for the 2nd LED
#define RED2 10
#define GREEN2 9
#define BLUE2 8
#define BACKLIGHT 45
/* Next line loads the LCD to pins that are displayed
LCD Pin 1(VSS): GN44D
LCD Pin 2(VDD): +5v
LCD Pin 3(Contrast): 330ohm resistor -> GND
LCD Pin 4(RS): Arduino 31
LCD Pin 5(RW): Arduino 33
LCD Pin 6(Enable): Arduino 35
LCD Pin 7(NoConnection):
LCD Pin 8(NoConnection):
LCD Pin 9(NoConnection):
LCD Pin 10(NoConnection):
LCD Pin 11(Data 4): Arduino 37
LCD Pin 12(Data 5): Arduino 39
LCD Pin 13(Data 6): Arduino 41
LCD Pin 15(Backlight +): Arduino 45
LCD Pin 16(Backlight GND): GND
-----------------------------------------
*/
LiquidCrystal lcd(31, 33, 35, 37, 39, 41, 43);
//Button class declaring button as a PULLUP button on pin 7
Button button = Button(7,PULLUP);

//Variables
//int BL = 45;    // pin 45 will control the backlight
// the score varible for calculating the score
int score = 0;
//The Variables applied to the Random LED
int redr = 0;
int grnr = 0;
int blur = 0;
//The variables applied to the Choice LED
int redc = 0;
int grnc = 0;
int bluc = 0;
// Boolean state variables
boolean stateGame = true;

int time = 1;
unsigned long timeSet = 0;
unsigned long refreshLCD = 0;
unsigned long refreshState = 0;
void setup()
{
  //Setup for the LCD
  pinMode(BACKLIGHT , OUTPUT);
  digitalWrite(BACKLIGHT, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20,4);
  lcd.clear();
 
  //Pinmodes for the Random LED
  pinMode(RED1, OUTPUT); //Pin 1 of LED
  pinMode(GREEN1, OUTPUT); //Pin 2 of LED
  pinMode(BLUE1, OUTPUT); //Pin 3 of LED
  //PinModes for the Choice LED
  pinMode(RED2, OUTPUT); //Pin 1 of LED2
  pinMode(GREEN2, OUTPUT); //Pin 2 of LED2
  pinMode(BLUE2, OUTPUT); //Pin 3 of LED2
  //Button for Start and stop
  pinMode(7, INPUT);
  //Seed Random Nubers for the rest of my program
  randomSeed(analogRead(0));
  
}

void loop()
{
   if(button.isPressed())
  {
    //Sets first LED and then starts the game.
    startLED1();
    //Starts the game function defined at the end. This way the
    //random colors will stay even when the game is cycleing
    startGame();
    // Calculates and displays the score
    scoreDisplay();
  }
  //delay(50);
}

void startLED1()
{
  redr = random(255);
  grnr = random(255);
  blur = random(255);
  analogWrite(RED1,redr);
  analogWrite(GREEN1,grnr);
  analogWrite(BLUE1,blur);
  stateGame = true;
}
void startGame()
{
  while(stateGame == true)
  {
    //A timer that is displayed on the LCD
    timeSet = millis() % 1000;
    if(timeSet == 0)
    {
      time = time + 1;
    }
    //Start allowing color changing with the 3 pots
    redc = map(analogRead(1), 0, 1023, 0, 255);
    grnc = map(analogRead(2), 0, 1023, 0, 255);
    bluc = map(analogRead(3), 0, 1023, 0, 255);
    analogWrite(RED2,redc);
    analogWrite(GREEN2,grnc);
    analogWrite(BLUE2,bluc);
    delay(0);
    refreshLCD = millis() % 60;
   //This displays the time, and variables of the colors chosen by
   // the pots on the LCD. You can use the LED and LCD to get as 
   //close as you can to the color
    if(refreshLCD == 0)
    {
      lcd.clear();
      lcd.setCursor(15,0);
      lcd.print("T:");
      lcd.setCursor(17,0);
      lcd.print(time);
      lcd.setCursor(0,0);
      lcd.print("R:");
      lcd.setCursor(2,0);
      lcd.print(redc);
      lcd.setCursor(0,1);
      lcd.print("G:");
      lcd.setCursor(2,1);
      lcd.print(grnc);
      lcd.setCursor(0,2);
      lcd.print("B:");
      lcd.setCursor(2,2);
      lcd.print(bluc);
    }
    refreshState = millis()%70;
    if(refreshState == 0 && button.isPressed())
    {
      stateGame = false;
    }
    //Tried but didn't work.
    //if(button.isPressed())
    //{
    //  stateGame = false;
    //}
  
  }  
}
// This is the function for the score.
void scoreDisplay()
{
   score = (time + abs(redr - redc) + abs(grnr - grnc) + abs(blur - bluc));
   lcd.clear();
   lcd.setCursor(4,1);
   lcd.print("Score: ");
   lcd.setCursor(11,1);
   lcd.print(score);
   delay(10000);
}

I need a way to use the milliseconds to start a timer when the startGame() is called.

I'm going to try something like

timer = millis() % 1;
if (timer == 0)
{
     time = timer % 1000;
     if(time == 0)
     {
          time = time + 1
     }
}

Something like that might work.. maybe. I report back in a few.

  while(stateGame == true)

The equality operator returns true or false, and exactly matches the value stored in stateGame, so the "== true" part of the statement is not needed.

      time = time + 1;

There's a really nifty little shortcut: http://arduino.cc/en/Reference/Increment

    timeSet = millis() % 1000;

The value stored in timeSet is the remainder when dividing the output from millis() by 1000. Suppose millis returns 980, 983, 988, 1001,... timeSet will not be 0, even though more than a second has gone by. You need to rethink this part of the code:

    if(timeSet == 0)
    {
      time = time + 1;
    }
    refreshLCD = millis() % 60;

Same issue as above.

    refreshState = millis()%70;
    if(refreshState == 0 && button.isPressed())
    {
      stateGame = false;
    }

Same issue, with an additional head scratcher. What is button? Does your game only have one switch? If that's the case, give it a meaningful name, like start or something. A button is used to keep a shirt from flapping in the breeze.

Also note this comment from the Button library page on the playground:

boolean uniquePress()

Checks to see if the state of the button has changed AND the button is pressed. This will only return true the first time the button has been pressed. (As opposed to the isPressed() which will return true as long as the button is pressed.

The isPressed function does not do debouncing. The uniquePress method does.

Ok. So I need a find a way to setup a timer without using delay, and without being entirely dependent on millis(). This is because if I use delay, I have a refresh problem and if I use millis() its dependent on the board itself, not when millis() is called... I can't think of any other ways to set up a timer. Given that it may skip numbers with a remainder of zero. My above idea wouldn't work for the same reason the others don't...

Well the unique press part of the program works. Now I just need a working timer.

Think about how you would do this with a watch, rather than a timer.

Suppose you want soft-boiled eggs, but not too soft. You like 4 minute eggs. You could get a timer that counted down 4 minutes. Start it when the water boils. When it runs out, turn the heat off.

Or you could stand there watching the water and your watch. Note what time it is when the water boils. Each time you think about it, subtract then (when the water started to boil) from now. Is that duration greater than 4 minutes? If so, turn the heat off. If not, do nothing.

so when or right before the startGame function starts I should capture the millis. Then during the function use that and subtract it from the current millis. I think I have figured it out.

Then during the function use that and subtract it from the current millis.

Exactly. You may want to have three copies of the time that the transition starts, to replace your %1000, %60 and %70 code. Change then to now as appropriate for all 3 contexts.

It works great now. It could still use some cleaning up, but it works great.
Thanks for all your help; I really appreciate it.

Here is the product.

A game in which you are shown a random color via a multi color LED,
then using the dials and LCD you try to make your LED as close as you can 
to the color of the other LED. Then your score will be calculated and displayed.
Press the button to start and to stop

*/
#include <LiquidCrystal.h> //Include the LiquidCrystal library
#include <Button.h> //Button library for better button control

//Color pins for the LED
#define RED1 13
#define GREEN1 12
#define BLUE1 11
//Color pins for the 2nd LED
#define RED2 10
#define GREEN2 9
#define BLUE2 8
#define BACKLIGHT 45
/* Next line loads the LCD to pins that are displayed
LCD Pin 1(VSS): GN44D
LCD Pin 2(VDD): +5v
LCD Pin 3(Contrast): 330ohm resistor -> GND
LCD Pin 4(RS): Arduino 31
LCD Pin 5(RW): Arduino 33
LCD Pin 6(Enable): Arduino 35
LCD Pin 7(NoConnection):
LCD Pin 8(NoConnection):
LCD Pin 9(NoConnection):
LCD Pin 10(NoConnection):
LCD Pin 11(Data 4): Arduino 37
LCD Pin 12(Data 5): Arduino 39
LCD Pin 13(Data 6): Arduino 41
LCD Pin 15(Backlight +): Arduino 45
LCD Pin 16(Backlight GND): GND
-----------------------------------------
*/
LiquidCrystal lcd(31, 33, 35, 37, 39, 41, 43);
//Button class declaring button as a PULLUP button on pin 7
Button button = Button(7,PULLUP);

//Variables
// the score varible for calculating the score
int score = 0;
//The Variables applied to the Random LED
int redr = 0;
int grnr = 0;
int blur = 0;
//The variables applied to the Choice LED
int redc = 0;
int grnc = 0;
int bluc = 0;
// Boolean state variables
boolean stateGame = true;
//Variables for time based functions
int time = 0;
unsigned long timeSet = 0;
unsigned long refreshLCD = 0;
void setup()
{
  //Setup for the LCD
  pinMode(BACKLIGHT , OUTPUT);
  digitalWrite(BACKLIGHT, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20,4);
  lcd.clear();
 
  //Pinmodes for the Random LED
  pinMode(RED1, OUTPUT); //Pin 1 of LED
  pinMode(GREEN1, OUTPUT); //Pin 2 of LED
  pinMode(BLUE1, OUTPUT); //Pin 3 of LED
  //PinModes for the Choice LED
  pinMode(RED2, OUTPUT); //Pin 1 of LED2
  pinMode(GREEN2, OUTPUT); //Pin 2 of LED2
  pinMode(BLUE2, OUTPUT); //Pin 3 of LED2
  //Button for Start and stop
  pinMode(7, INPUT);
  //Seed Random Nubers for the rest of my program
  randomSeed(analogRead(0));
}
void loop()
{
  if(button.isPressed())
  {
    startLED1(); //Sets first LED and then starts the game.
    
    //Starts the game function defined at the end. This way the
    //random colors will stay even when the game is cycleing
    timeSet = millis();
    startGame();
     scoreDisplay();  // Calculates and displays the score
  }
  delay(100);
}
//Gets random colors, sets those colors to the LED and sets the condtion for the next loop.
void startLED1()
{
  redr = random(255);
  grnr = random(255);
  blur = random(255);
  analogWrite(RED1,redr);
  analogWrite(GREEN1,grnr);
  analogWrite(BLUE1,blur);
  stateGame = true;
}
void startGame()
{
  while(stateGame)
  {
    //A timer that is displayed on the LCD
    time = (millis() - timeSet)/1000;
    //Start allowing color changing with the 3 pots
    redc = map(analogRead(1), 0, 1023, 0, 255);
    grnc = map(analogRead(2), 0, 1023, 0, 255);
    bluc = map(analogRead(3), 0, 1023, 0, 255);
    analogWrite(RED2,redc);
    analogWrite(GREEN2,grnc);
    analogWrite(BLUE2,bluc);
    refreshLCD = millis() % 60;
   //This displays the time, and variables of the colors chosen by
   // the pots on the LCD. You can use the LED and LCD to get as 
   //close as you can to the color
    if(refreshLCD == 0)
    {
      lcd.clear();
      lcd.setCursor(15,0);
      lcd.print("T:");
      lcd.setCursor(17,0);
      lcd.print(time);
      lcd.setCursor(0,0);
      lcd.print("R:");
      lcd.setCursor(2,0);
      lcd.print(redc);
      lcd.setCursor(0,1);
      lcd.print("G:");
      lcd.setCursor(2,1);
      lcd.print(grnc);
      lcd.setCursor(0,2);
      lcd.print("B:");
      lcd.setCursor(2,2);
      lcd.print(bluc);
    }
    if(button.uniquePress())// Checks to see if the button is pessed again
    {                       // if it is the main loop condition is broken and stops the loop.
      stateGame = false;
      delay(100);
    }
  }
}
// This is the function for the score.
void scoreDisplay()
{
   score = (time + abs(redr - redc) + abs(grnr - grnc) + abs(blur - bluc));
   lcd.clear();
   lcd.setCursor(4,1);
   lcd.print("Score: ");
   lcd.setCursor(11,1);
   lcd.print(score);
   delay(250);
}