Loop issues on my Linear Actuator Project

I am working on a project attempting to control a linear actuator with an Arduino joystick and an Arduino Uno. I have the linear actuator working and it does what I want it to do when the joystick is moved in a certain direction but only if the condition is during the upload of the code. Once I release the joystick the code is unresponsive. I would like it to be on a continuous loop so that it may be able to be manually moved back and forth while initiating programs by moving the joystick left or right. Please help. On the serial monitor, it shows the initial position of the joystick when the code is uploaded but it doesn’t refresh which is why I think there is something canceling the loop somewhere.

HERE IS THE CODE

// defines pins numbers
const int stepPin = 5;
const int dirPin = 4;
const int enPin = 8;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 1; // analog pin connected to X output
const int Y_pin = 0; // analog pin connected to Y output
void setup() {

// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);

pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200);

}
void loop() {
Serial.print(“Switch: “);
Serial.print(digitalRead(SW_pin));
Serial.print(”\n”);
Serial.print(“X-axis: “);
Serial.print(analogRead(X_pin));
Serial.print(”\n”);
Serial.print(“Y-axis: “);
Serial.println(analogRead(Y_pin));
Serial.print(”\n\n”);

while (analogRead(Y_pin)<300){
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);

}

while(analogRead(Y_pin)>700){
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);

}

if (analogRead(X_pin) < 300){

digitalWrite(dirPin,LOW); //Changes the rotations direction toward the motor

for(int x = 0; x < 3750; x++) {
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
}

delay(5000);

digitalWrite(dirPin,HIGH); // Enables the motor to move away from the motor
//1500~2mm
for(int x = 0; x < 3750; x++) {
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
}
delay(5000); // One second delay
}
else if(analogRead(X_pin) > 700){

}
int SW_sig = digitalRead(SW_pin);
while(SW_sig = HIGH) {
digitalWrite(enPin,HIGH);
}
}

Here is one obvious problem. The loop below will never stop.

 while(SW_sig = HIGH) {
    digitalWrite(enPin,HIGH);
    }

should be:

 while(SW_sig == HIGH) {
    digitalWrite(enPin,HIGH);
    }

Also, use the auto format feature in the IDE and post your code in code blocks.

Here is your code reformatted to make it more readable:

// defines pins numbers
const int stepPin = 5; 
const int dirPin = 4; 
const int enPin = 8;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 1; // analog pin connected to X output
const int Y_pin = 0; // analog pin connected to Y output

void setup() 
{
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);

  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(115200);
}

void loop() 
{
  Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print("\n");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print("\n");
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_pin));
  Serial.print("\n\n");

  while (analogRead(Y_pin)<300)
  {
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
  }

  while(analogRead(Y_pin)>700)
  {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(500); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(500);  
  }
 
  if (analogRead(X_pin) < 300)
  {

    digitalWrite(dirPin,LOW); //Changes the rotations direction toward the motor
     
    for(int x = 0; x < 3750; x++) 
    {
     digitalWrite(stepPin,LOW);
     delayMicroseconds(500);
     digitalWrite(stepPin,HIGH);
     delayMicroseconds(500);
    }
    
    delay(5000);
    
    digitalWrite(dirPin,HIGH); // Enables the motor to move away from the motor
    //1500~2mm
    for(int x = 0; x < 3750; x++) 
    {
      digitalWrite(stepPin,LOW); 
      delayMicroseconds(500); 
      digitalWrite(stepPin,HIGH); 
      delayMicroseconds(500); 
    }
    delay(5000); // One second delay
  }
  else if(analogRead(X_pin) > 700)
  {

  }
  
  int SW_sig = digitalRead(SW_pin);
  while(SW_sig = HIGH) 
  {
    digitalWrite(enPin,HIGH);
  }
}

Thank you ToddL1962
Sorry about that this is my first time using the Arduino forum. I corrected that and it helped a lot. would that cause the loop to cancel?

wrp1997:
Thank you ToddL1962
Sorry about that this is my first time using the Arduino forum. I corrected that and it helped a lot. would that cause the loop to cancel?

Not sure what you mean by "cancel" but what happens is that loop becomes an "infinite" loop so it just sits there looping until you unplug the board, reset the board, or re-upload code.