A necessary and sufficient condition for convergence of real-valued functions