Unable to jump out of a loop

Good day everyone. I am currently working on a dispensing project. I have tried and change the code several different times to try and get the last part working but i seem to not get something here. I think i am missing out on something but i just cant seem to figure it out. All help is greatly appreciated!
I have included a // i am stuck here in the code so that it is easier to see the where the problem lies. The conveyor is moving forward and the lcd displays " dispensing done , packagning now…" and it seems that the programe is stuck in that loop afterwards. It does not sense my sensor at the end ( it is an IR sensor) . Another problem is why does my lcd display ‘gramss’ instead of ‘grams’ at the middle of my programe? I cant seem to find the solution for this as well. I have added a // lcd printing wrongly here
at that part of the problem .Thank you! (i have taken the subroutines out as i have exceeded the max char and i have also checked that my IR sensor at the end is working)

#include <LiquidCrystal.h>
#include <Keypad.h>
#include "HX711.h"  //You must have this library in your arduino library folder
int Conveyor1 = 53;
int Conveyor2 = 22;


int cupdispense = 39;
int cupdispense2 = 36;
int cupdispensespeed = 38;

int liddispensespeed = 37;
int liddispense = 34;
int liddispense2 = 35;

int stamp=26;
int stamp2=45;


#define DOUT  9
#define CLK  8

int grams = 0;
int sol1 = 40;
int sol2 = 41;
int sol3 = 42;
int buzzer = A2;
HX711 scale(DOUT, CLK);
float calibration_factor = -90470;
//Change this calibration factor as per your load cell once it is found you many need to vary it in thousands

const byte rows = 4; //four rows
const byte cols = 3; //three columns
char keys[rows][cols] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[rows] = {A3, A4, A5, A6}; //connect to the row pinouts of the keypad left first 4
byte colPins[cols] = {A7, A8, A9 }; //connect to the column pinouts of the keypad right last 3=
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int myValue = 0 ;
int myValue2 = 0;
int i;
int sensor1 = 46;
int sensor1val;

int sensor2 = 47;
int sensor2val;

int sensor3 = 48;
int sensor3val;

int endsensor = 23;
int endsensorval;

int startsensor = 31;
int startsensorval;

int scaleval =0; 
int counter = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(sensor1, INPUT_PULLUP);
  pinMode(sensor2, INPUT_PULLUP);
  pinMode(sensor3, INPUT_PULLUP);
  Serial.println("Press T to tare");
  scale.set_scale(-90470);  //Calibration Factor obtained from first sketch
  scale.tare();             //Reset the scale to 0
  pinMode(Conveyor1, OUTPUT); // 53
  pinMode(Conveyor2, OUTPUT); // 52
  pinMode(sol1, OUTPUT); // item 1
  pinMode(sol2, OUTPUT); // item2
  pinMode(sol3, OUTPUT); //item3
  pinMode(cupdispense, OUTPUT);
  pinMode(cupdispense2, OUTPUT);
  pinMode(liddispense, OUTPUT);
  pinMode(liddispense2, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(startsensor, INPUT_PULLUP);
  pinMode(endsensor, INPUT_PULLUP);
  pinMode(stamp, OUTPUT);
  pinMode(stamp2,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  startsensorval = digitalRead(startsensor);
  if (startsensorval == LOW && counter==0 )
  {
    ConveyorStop();
 

    
  lcd.setCursor(0, 0);
  lcd.write ("Welcome!");
  lcd.display();
  delay(800);
  lcd.setCursor(0, 1);
  lcd.write("Select item no.");
  lcd.display();
     counter=1;
  }

  startsensorval = digitalRead(startsensor);
  if (startsensorval == HIGH && counter==0 )
  {
    ConveyorBackward();
  

 Serial.print("ct0");
  lcd.setCursor(0, 0);
  lcd.write ("Welcome!");
  lcd.display();
  delay(800);
  lcd.setCursor(0, 1);
  lcd.write("Select item no.");
  lcd.display();
  counter=1;
  }
  char key = keypad.getKey ();
  if (key == '1')
  {
    enter();
    lcd.clear();
    delay(500);
    lcd.setCursor(0, 0);
    lcd.write( "You selected");
    lcd.display();
    lcd.setCursor(0, 1);
    lcd.write("Item 1");
    lcd.display();
    delay(1000);

    lcd.clear();

    startsensorval = digitalRead(startsensor);
    while (startsensorval == LOW && counter == 1)
    {
      lcd.setCursor(0, 0);
      lcd.write("Enter weight");
      lcd.display();
      char key = keypad.getKey ();
      if ( key != NO_KEY)
      {
        enter();
        key = key - 48;
        myValue = ( myValue * 10 ) + key ;
        lcd.setCursor(0, 1);
        lcd.print(myValue);
        lcd.print(" Grams");
        lcd.display();
      }
      if (key == -6)
      {
        enter();
        lcd.setCursor(0, 1);
        lcd.clear();
        lcd.display();
        myValue = 0;
      }

      if ( key == -13)
      {
        enter();

        lcd.clear();

        lcd.setCursor (0, 0);
        lcd.write( "You have entered ");
        lcd.display();
        myValue = (myValue  + 13 + 6) / 10;
        lcd.setCursor(0, 1);
        lcd.print(myValue);
        lcd.print(" Grams");   // 
        lcd.display();
        delay(3000);
        cupforward();
        delay(3500);
        cupbackward();
        delay(3500);
        cupstop();
        counter = 2;
         sensor1val = digitalRead(sensor1);
      }
    }


    lcd.clear();
    sensor1val = digitalRead(sensor1);
    while (sensor1val==HIGH&& counter == 2)
    {
      Serial.print("ct2");
      ConveyorForward();
      lcd.setCursor(0, 0);
      lcd.write("Processing....");
      lcd.display();
      sensor1val = digitalRead(sensor1);
         if(sensor1val == LOW  ) //1st option sensor & the first solenoid
    {
       sensor1val = digitalRead(sensor1);
      ConveyorStop();
      
    }
    }
    sensor1val = digitalRead(sensor1);
    lcd.clear();  
      while (grams < myValue && sensor1val==LOW) 
      {
     Serial.print("Grams<myvalue");
        grams = (scale.get_units(8) * 1000) ;
            if (scaleval== 0)
        {
          scale.tare();
          scaleval=1;
        }
        lcd.setCursor(0,0);
        lcd.write("Weight: ");
        lcd.display();
        lcd.setCursor(0,1);
        lcd.print(grams);  //Up to 3 decimal points
        lcd.print(" gram"); // LCD not displaying properly here
        lcd.display();
        digitalWrite(sol1, HIGH);
        counter = 3 ;    
  
      } // try dont close this

      lcd.clear();
      delay(100);
    while( grams >= myValue && counter == 3 ) // i am stuck in this loop
      {
             ConveyorForward();
        lcd.setCursor(0,0);
        lcd.write("Dispensing done!");
        lcd.display();
           lcd.setCursor(0,1);
        lcd.write("Packaging now..");
        lcd.display();
        digitalWrite(sol1, LOW);
             grams = (scale.get_units(8) * 1000) ;
        counter=4;
         endsensorval=digitalRead(endsensor);
      Serial.print("ct4");
      }
      endsensorval=digitalRead(endsensor);


while(endsensorval==LOW && counter==4 && grams>=myValue)
  {
 // does not read sensor4==LOW to stop conveyor and run remaining codes
   ConveyorStop();
        lidstart();
        delay(30);
        lidstop();
        counter=5;
  Serial.print(" ct5");
  endsensorval=digitalRead(endsensor);
  while(endsensorval==LOW && counter==5)
  {
    if( grams < 15  )
    {
       Serial.print("Final");
      startsensorval=digitalRead(startsensor);
    }
   }
  }
 }
}
    while( grams >= myValue && counter == 3 ) // i am stuck in this loop
      {
             ConveyorForward();
        lcd.setCursor(0,0);
        lcd.write("Dispensing done!");
        lcd.display();
           lcd.setCursor(0,1);
        lcd.write("Packaging now..");
        lcd.display();
        digitalWrite(sol1, LOW);
             grams = (scale.get_units(8) * 1000) ;
        counter=4;

You can't possibly be stuck in this while statement, since it will iterate 0 or 1 times. It is pointless to use a while loop that can never iterate more than once.

Why does your code look like it was typed by a drunken monkey?

Use Tools + Auto Format, if you can't be bothered to keep the code lined up as you go.

Your loop() function is WAY too long. Most of that code belongs in functions.

You should reformat the code to make it more readable.

I agree with @PaulS. You have at least two while loops that will only be executed 0 or 1 times. What makes you think you are stuck in the loop you marked?

Which specific statement is outputting "gramss" on the LCD.

You seem to be using 'counter' to determine what state the program is in, perhaps you should call the variable 'state'. Maybe you could restructure the code using a case statement based on the value of 'state' and put the relevant code for each case in a function. That might make the functionality clearer.

Unable to jump out of a loop

I have just looked very briefly at your code.

If you want to have a responsive program then the answer is NOT to have loops apart from the standard loop() function.

Your program has a lot of WHILE loops each of which will block the Arduino until it completes. In most cases WHILE can be replaced with IF and then allow loop() to do the iteration.

...R Planning and Implementing a Program