File read is happening even after end of file

Hi All,

I am doing a file read operation, using a while loop. Even after the end of file is reached the while is still executing. Here is the code:

while (!$feof(file2))begin
             $fscanf(file2, "%d %d %d %d %d" , col1, col2, col3, col4, col5);
             //`uvm_info(get_type_name(),"Reading file2",UVM_LOW)
             offset_data_i = '{col1 , col2, col3, col4, col5};
             itr = offset_data_i[0];
             cnt = cnt + 1;
             `uvm_info(get_type_name(),$sformatf("Value of count = %0d",cnt),UVM_LOW)
         end //while (!$feof(file2))

The file has 1440388 lines, my count value is going beyond this.

Can somebody let me know what is the issue and why this happens?

Regards,
Abhinandan

Why it’s bad to use feof() to control a loop