Program stuck 4-digit 7-segment display

I`m doing program for stopwatch but I always encounter this problem. I always stuck at ‘while(true)’ statement. It plays tone in procedure, but nothing else. This program is not final version.

//Pins 0 & 1 reserved for data transfer
const int dig1 = 2; //D2
const int dig2 = 3; //D3
const int dig3 = 4; //D4
const int dig4 = 5; //D5
const int segA = 6; //D6
const int segB = 7; //D7
const int segC = 8; //D8
const int segD = 9; //D9
const int segE = 10; //D10
const int segF = 11; //D11
const int segG = 12; //D12
const int segDP = 13; //D13
const int statPin = 14; //A0
const int mode0Pin = 15; //A1
const int mode1Pin = 16; //A2
const int mode2Pin = 17; //A3
const int mode3Pin = 18; //A4
const int piezo = 19; //A5

const int m0 = 5;
const int m1 = 6;
const int m2 = 7;
const int m3 = 8;
//Consts 15,20,25

unsigned int timeNow = 0;
int digits[4] = {0, 0, 0, 0};
int currentMode = 0;
boolean statNow = false;
int CMST = 0;
int enum1, enum2, enum3, enum4 = 0;
int a = 1;

void setup(){
 pinMode(dig1, OUTPUT);
 pinMode(dig2, OUTPUT);
 pinMode(dig3, OUTPUT);
 pinMode(dig4, OUTPUT);
 
 pinMode(segA, OUTPUT);
 pinMode(segB, OUTPUT);
 pinMode(segC, OUTPUT);
 pinMode(segD, OUTPUT);
 pinMode(segE, OUTPUT);
 pinMode(segF, OUTPUT);
 pinMode(segG, OUTPUT);
 pinMode(segDP, OUTPUT);
 
 pinMode(statPin, INPUT);
 pinMode(mode0Pin, INPUT);
 pinMode(mode1Pin, INPUT);
 pinMode(mode2Pin, INPUT);
 pinMode(mode3Pin, INPUT);
 HIITInit();
 if(currentMode == 1){ stopwatch(); }
 else { hiit(currentMode); }
}

void loop(){
}

void hiit(int CMS){
 
}

void stopwatch(){
 delay(1000);
 timeNow = 0;
 tone(piezo, 350);
 delay(250);
 noTone(piezo);
 
 while(true){
  enum1 = timeNow / 1000;
  enum2 = timeNow % 1000 / 100;
  enum3 = timeNow % 100 / 10;
  enum4 = timeNow % 10;
  
  for(int x; x < 251; x++){
   en(1);
   num(enum1);
   delay(1);
   en(2);
   num(enum2);
   delay(1);
   en(3);
   num(enum3);
   delay(1);
   en(4);
   num(enum4);
   delay(1);
  }
  
  timeNow++; 
 }
}

void HIITInit(){
 allHi();
 delay(1000);
 clearAll();
 en(1);digitalWrite(segA, 1);digitalWrite(segD, 1);digitalWrite(segG, 1);
 
 while(statNow == false){

   if(digitalRead(statPin) == HIGH){
   currentMode = 1;
   statNow = true; 
   clearAll();
  }
  
  else if(digitalRead(mode0Pin) == HIGH){
   currentMode = 2;
   statNow = true; 
  }
  
  else if(digitalRead(mode1Pin) == HIGH){
   currentMode = 3;
   statNow = true; 
  }
  
  else if(digitalRead(mode2Pin) == HIGH){
   currentMode = 4;
   statNow = true;
  }
  
  else if(digitalRead(mode3Pin) == HIGH){
   currentMode = 5;
   statNow = true; 
  }
 }
}

void clearAll(){
 digitalWrite(dig1, 1);
 digitalWrite(dig2, 1);
 digitalWrite(dig3, 1);
 digitalWrite(dig4, 1);
 
 digitalWrite(segA, 0);
 digitalWrite(segB, 0);
 digitalWrite(segC, 0);
 digitalWrite(segD, 0);
 digitalWrite(segE, 0);
 digitalWrite(segF, 0);
 digitalWrite(segG, 0);
 digitalWrite(segDP, 0);
}

void allHi(){
 digitalWrite(dig1, 0);
 digitalWrite(dig2, 0);
 digitalWrite(dig3, 0);
 digitalWrite(dig4, 0);
 
 digitalWrite(segA, 1);
 digitalWrite(segB, 1);
 digitalWrite(segC, 1);
 digitalWrite(segD, 1);
 digitalWrite(segE, 1);
 digitalWrite(segF, 1);
 digitalWrite(segG, 1);
 digitalWrite(segDP, 1);
}

void digsLo(){
 digitalWrite(dig1, 1);
 digitalWrite(dig2, 1);
 digitalWrite(dig3, 1);
 digitalWrite(dig4, 1);
}

void numsLo(){
 digitalWrite(segA, 0);
 digitalWrite(segB, 0);
 digitalWrite(segC, 0);
 digitalWrite(segD, 0);
 digitalWrite(segE, 0);
 digitalWrite(segF, 0);
 digitalWrite(segG, 0);
 digitalWrite(segDP, 0); 
}

void en(int pin){
 switch (pin) {
  case 1:
   digsLo();
   digitalWrite(dig1, 0);
  break;
  
  case 2:
   digsLo();
   digitalWrite(dig2, 0);
  break;
  
  case 3:
   digsLo();
   digitalWrite(dig3, 0);
  break;
  
  case 4:
   digsLo();
   digitalWrite(dig4, 0);
  break;
 } 
}

void num(int numData){
 switch(numData){
  default:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
   digitalWrite(segD, 1);
   digitalWrite(segE, 1);
   digitalWrite(segF, 1);
  break;
  case 1:
   numsLo();
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
  break;
  case 2:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segB, 1);
   digitalWrite(segD, 1);
   digitalWrite(segE, 1);
   digitalWrite(segG, 1);
  break;
  case 3:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
   digitalWrite(segD, 1);
   digitalWrite(segG, 1);
  break;
  case 4:
   numsLo();
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
   digitalWrite(segF, 1);
   digitalWrite(segG, 1);
  break;
  case 5:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segC, 1);
   digitalWrite(segD, 1);
   digitalWrite(segF, 1);
   digitalWrite(segG, 1);
  break;
  case 6:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segC, 1);
   digitalWrite(segD, 1);
   digitalWrite(segE, 1);
   digitalWrite(segF, 1);
   digitalWrite(segG, 1);
  break;
  case 7:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
  break;
  case 8:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
   digitalWrite(segD, 1);
   digitalWrite(segE, 1);
   digitalWrite(segF, 1);
   digitalWrite(segG, 1);
  break;
  case 9:
   numsLo();
   digitalWrite(segA, 1);
   digitalWrite(segB, 1);
   digitalWrite(segC, 1);
   digitalWrite(segD, 1);
   digitalWrite(segF, 1);
   digitalWrite(segG, 1);
  break;
 } 
}

Thanks for help.

0xN35T:
I always stuck at 'while(true)' statement.

while(true)

So, what's the condition to be met? While what is true?

Somewhere in Arduino Starter Kit was written that ‘while(true){}’ will make an infinite loop.

Apart from the while true issue, or non-issue, there has to be a better way of running the 4x7 than what you are doing. The first thing you need to impart is whether you have a common cathode or common anode display. If cathode, the following might be helpful

http://playground.arduino.cc/Main/MAX72XXHardware

if you have common anode, I understand there is a similar approach, using LM 7221. Either way will surely give you some relief from banging your head against the brickwork.

  for(int x; x < 251; x++){

You haven’t initialized x. It will probably be a random value on the stack.

Pete

el_supremo:

  for(int x; x < 251; x++){

You haven't initialized x. It will probably be a random value on the stack.

Pete

Really thank you. Solved mine problem fast and simple. Hope it will help someone else who have this problem too.