Shortest cycle in undirected graph

consider a graph with 5 nodes and edges are
(1,2) (1,3) (2,4) (2,5) and (3,5)

if we are at node 5 neighbors of 5 are 2,3(which are already visited). now if we see else if condition dis[nbr] >=dis[cur] this condition fails for node 3 since dis[nbr] = 1 and dis[cur]=2 but node 3 and 5 have back edge why condition is failing here but code works fine with this condition.Am I missing something?Please correct me.

it simply means that the ans will not be updated, so the current ans will remain the same in this condition
and if it is not updated then the value will not change and at the end ans will not be equal to n-1 and hence this will still give the cycle
because it will be updated for the case in 3
when 5 will be encountered with 2 and then again when 5 will again be encountered from 3 it will give the correct answer there since 5 will already be visited so the else if becomes true and ans is updated