title: While loop in stored procedure loops only twice instead of 8 times
body: <p><strong>Table checkval</strong></p>
  
  <pre><code>val
  ----
  5705
  5704
  5703
  5702
  5701
  </code></pre>
  
  <p><strong>Stored Procedure</strong></p>
  
  <pre><code>BEGIN
      DECLARE x INT;
  DECLARE done INT DEFAULT FALSE;
      DECLARE myType INT;
      DECLARE cur1 CURSOR FOR select val from checkval;
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  
      SET x = 10;
  
      WHILE x  &gt;= 2 DO
  ##############
  
      OPEN cur1;
  
      read_loop: LOOP
          IF done THEN
              LEAVE read_loop;
          END IF;
  
          FETCH cur1 INTO myType;
          insert into myType values (myType);
  
  
      END LOOP read_loop;                              
  CLOSE cur1;
          SET  x = x-1; 
  
      ##################
      END WHILE;
  
  END
  </code></pre>
  
  <p><strong>Current Output</strong></p>
  
  <pre><code>5705
  5704
  5703
  5702
  5701--Loops only twice
  5705
  5704
  5703
  5702
  5701
  </code></pre>
  
  <p><strong>Desired Output</strong></p>
  
  <pre><code>5705 - Loops 8 times
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  5705
  5704
  5703
  5702
  5701
  </code></pre>
  
  <p>Why is it even when I specify a while loop starting at <code>10</code> and ending at <code>2</code>, do I get my output only looped twice in the target table. I was hoping to see it repeated 8 times. Can yo pls help?</p>