This is a program to compute square root of a positive number.

How do I prevent this program to loop forever?Code:double sqrt(double num) { if (num < 0) return 0; double guess = num/2, oldguess = 0; while(guess != oldguess) { oldguess = guess; guess = (num/guess + guess)/2; } return guess; }