DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `calculateGraceMarkTwo`()
BEGIN
-- declare VARIABLES as per the below CURSOR
DECLARE v_StuID int(11) DEFAULT 0;
DECLARE v_StuFname VARCHAR (255) DEFAULT "";
DECLARE v_StuLname VARCHAR (255) DEFAULT "";
DECLARE v_StuCID int(11) DEFAULT 0;
DECLARE v_StuMrk int(11) DEFAULT 0;
-- declaration for not found handler
DECLARE v_finished INTEGER DEFAULT 0;
-- declare one variable to capture the full mark and passmark of the SUBJECT
DECLARE v_CFullmark INTEGER DEFAULT 0;
DECLARE v_CPassmark INTEGER DEFAULT 0;
DECLARE v_Grace FLOAT DEFAULT 0.00;
-- declare variable to insert into final table student_mark
DECLARE SName VARCHAR(255) default "";
DECLARE CName VARCHAR(255) DEFAULT "";
DECLARE IMark FLOAT DEFAULT 0.00;
DECLARE TMark FLOAT DEFAULT 0.00;
DECLARE Result VARCHAR(10) default "";
DECLARE Remark VARCHAR(25) default "";

-- Declare Cursor for this
DECLARE student_cursor CURSOR FOR select s.Student_Id, s.Student_Fname, s.Student_Lname,s.Course_Id,s.Mark_Obtained,c.Full _Mark , c.Pass_Mark,c.Grace_Per,c.Course_Name
from student s ,course c
where s.Course_id = c.Course_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished =1;

-- Open the CURSOR

OPEN student_cursor;

-- now start the LOOP

calculate_mark: LOOP

FETCH student_cursor INTO v_StuID,v_StuFname,v_StuLname,v_StuCID,v_StuMrk,v_ CFullmark,v_CPassmark,v_Grace,CName;

SET SName = CONCAT(v_StuFname ," ", v_StuLname);
-- SET CName = (select Course_Name FROM course where Course_Id = v_StuCID);
SET IMark = v_StuMrk+(v_CFullmark * (v_Grace/100));

IF IMark >= v_CPassmark THEN
SET Result = 'PASS';
SET Remark = 'Grace Applied';
INSERT INTO student_mark(Stu_Name, Course_Name,Mark_Secured,Result,Remarks) VALUES(SName, CName,IMark,Result,Remark);
ELSE
SET Result = 'FAIL';
SET Remark = 'Grace Applied';
INSERT INTO student_mark(Stu_Name, Course_Name,Mark_Secured,Result,Remarks) VALUES(SName, CName,IMark,Result,Remark);
END IF;

END LOOP ;

CLOSE student_cursor;
END

*****************
Basically it's calculating correctly for all the records. But loop is not terminating for the last record and running infinite times.

select * from student_mark

Records in student_mark table:

# Stu_Name, Course_Name, Mark_Secured, Result, Remarks
'Bhabesh Sahoo', 'Mathematics', '101', 'PASS', 'Grace Applied'
'Jitendra Sahoo', 'Physics', '72', 'PASS', 'Grace Applied'
'Romakanta Patro', 'Chemistry', '66', 'PASS', 'Grace Applied'
'Tarakanath Shimadri', 'Botany', '30', 'PASS', 'Grace Applied'
'Sudhansu Parida', 'Zoology', '97.5', 'PASS', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'
'Amit Agarawal', 'Zoology', '12.5', 'FAIL', 'Grace Applied'

Please guide me where this is going wrong.