Void loop does not exicuite all lines.

When run, function HeadMovement runs properly, but function BodyMovement does not run at all.
If i comment out Headcount, BodyMovement runs fine.
Would you let me know why?

Thanks
Mug

/*-----( Import needed libraries )-----*/



/*-----( Declare Constants and Pin Numbers )-----*/
  //variables
int where = 0;
int angle = 0;
int Mcount = 0;
int Headcount = 0;
int Bodycount = 0;
int moveit;
int Scanspeed = 2;
int Seperation = 0;
int TheWayHome;
boolean direct = true;
boolean HeadInterlock;
boolean BodyInterlock;

  // token pins
int headmotorD = 6;     // Dir, Head Motor
int headmotorS = 5;     // Step, Head Motor
int bodymotorD = A1;     // Dir, Body Motor
int bodymotorS = A2;     // Step, Body Motor
int sensor7 = 8;           // Sensor 7, R&L, 180 Deg
int sensor1 = 9;           // Sensor 1, DRight, 30 Deg
int sensor2 = 10;          // Sensor 2, DRight, 90 Deg
int sensor3 = 11;          // Sensor 3, DRight, 1200 Deg
int sensor4 = 12;          // Sensor 4, DLeft, 30 Deg
int sensor5 = 13;          // Sensor 5, DLeft, 90 Deg
int sensor6 = A0;          // Sensor 6, DLeft, 120 Deg
int HIL = 3;              //Head Interlock
int BIL = 4;              //Body Interlock 
int voice = A4;           // Voice Box
int gun = A5;             // Gun Solinoid
int Shutdown = A3;
//int direct = 0;


void setup() {
  //declare the motor pins, voice, gun as outputs, sensor pins as input
 pinMode(headmotorD, OUTPUT);
 pinMode(headmotorS, OUTPUT);
 pinMode(bodymotorD, OUTPUT);
 pinMode(bodymotorS, OUTPUT);
 pinMode(sensor1, INPUT);
 pinMode(sensor2, INPUT);
 pinMode(sensor3, INPUT);
 pinMode(sensor4, INPUT);
 pinMode(sensor5, INPUT);
 pinMode(sensor6, INPUT);
 pinMode(sensor7, INPUT);
 pinMode(HIL, INPUT);
 pinMode(BIL, INPUT);
 pinMode(voice, OUTPUT);
 pinMode(gun, OUTPUT);
 pinMode(Shutdown, OUTPUT);
 
digitalWrite(Shutdown, HIGH);

//TheWayHome = GoneHome();  
}


void loop() {
  

  
direct=TRUE;
Mcount=2;


  Headcount=HeadMovement(direct, Mcount);



  Bodycount=BodyMovement(direct, Mcount);


}


int HeadMovement(int x, int y)
{
  if (x == true)
    {
     digitalWrite(headmotorD,LOW);  //CW
    }
  else
    {
     digitalWrite(headmotorD,HIGH);  //CCW 
    }
 for (int point = 0; y; point++)
  {
   digitalWrite(headmotorS,HIGH);
   delay(10);
   digitalWrite(headmotorS,LOW);
   delay(10);
   if (x==true) {Headcount = Headcount + 1;}
   if (x==false) {Headcount = Headcount - 1;}
  }
return Headcount;
}

 
int BodyMovement(int x, int y)
{
  if (x == true)
    {
     digitalWrite(bodymotorD,LOW);  //CW
    }
  else
    {
     digitalWrite(bodymotorD,HIGH);  //CCW 
    }
 for (int point = 0; y; point++)
  {
   digitalWrite(bodymotorS,HIGH);
   delay(10);
   digitalWrite(bodymotorS,LOW);
   delay(10);
   if (x==true) {Bodycount = Bodycount + 1;}
   if (x==false) {Bodycount = Bodycount - 1;}
  }
return Bodycount;
}

direct=TRUE;Unusual.

for (int point = 0; y; point++)Ditto

 for (int point = 0; y; point++)
  {
   digitalWrite(headmotorS,HIGH);
   delay(10);
   digitalWrite(headmotorS,LOW);
   delay(10);
   if (x==true) {Headcount = Headcount + 1;}
   if (x==false) {Headcount = Headcount - 1;}
  }

The for loop will continue to execute while 'y' is non-zero. On entry to the function it will be 2 but after that there's nothing that ever sets it to zero, so guess what happens?

Pete

direct=TRUE;: This is directional, TRUE == Clockwise, FALSE==Counter Clockwise. for (int point = 0; y; point++): Don't understand this as unusual, It came from Ardunio reference.

It's an odd spelling of "true". I'd like to see the reference to the for loop, please.

Thank you, el_supremo, Awol, that's the problem, I see it now. Yep about TRUE, SB true.

I rechecked the reference, and had it wrong. AWOL Your initial post was a bit vague but it all helped in the end, Again, thank you.

It wasn't vague, I pointed out the exact line that was incorrect. If the code had compiled (the posted code was obviously incomplete, so I couldn't replicate the problem), then there was clearly no syntactical error. The idea was to get you to go away and see why the highlighted code was incorrect.

Some simple debug prints would have allowed you to narrow-down the problem.

/*-----( Import needed libraries )-----*/

You are NOT programming the Arduino using Java. C does NOT import libraries.