'While loop is not stopping in arduino [closed]

I am applying a while loop, but the loop does not stop. Also, the serialmonitor stops writing values. Why is that? Also the stop command is not working. Below is my code

while (x <= Y) //Y is a constant integer, x is defined formulaically earlier 
  {
    digitalWrite(SPin, HIGH);
    //motor running code  
    digitalWrite(dir1,HIGH);
    digitalWrite(dir2,LOW);
    analogWrite(speedPin,mSpeed);
    Serial.println(x);
    delay(50);
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source