changed for loop to while loop in newton raphson