title: MYSQL cursor loop, runs one extra round, why?
body: <p>I'm looping through a cursor result set in a MYSQL stored procedure. I'm facing an issue which is that the loop always run thorough the last record twice. Here is my code,</p>
  
  <pre><code>BEGIN
  DECLARE not_found_creadit INT DEFAULT 0;
  
  DECLARE cur_credit CURSOR FOR 
  SELECT customer_id, amount, status, user_type, employee, note FROM credit WHERE status = 'approved' AND customer_id = int_cust_id;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET not_found_creadit = 1;
  OPEN cur_credit;
    SET not_found_creadit = 0;
    credit_loop : LOOP 
        IF not_found_creadit THEN
          CLOSE cur_credit;
          LEAVE credit_loop;
        END IF;
        FETCH cur_credit INTO vc_customer, dec_amount, vc_status, vc_user_type, vc_emp, vc_note;
        SELECT vc_customer, dec_amount, vc_status, vc_user_type, vc_emp, vc_note;
        ......
        ......
    END LOOP;
  END;
  </code></pre>
  
  <p>Means if I have 3 records, loop runs 4 times, if it is 10 records loop runs 11 times, etc. Any idea whats happening here?</p>