An iterative phase retrieval method for nonperiodic objects has been developed from the charge-flipping algorithm proposed in crystallography. A combination of the hybrid input-output (HIO) algorithm and the flipping algorithm has greatly improved performance. In this combined algorithm the flipping algorithm serves to find the support (object boundary) dynamically, and the HIO part improves convergence and moves the algorithm out of local minima. It starts with a single intensity measurement in the Fourier domain and does not require a priori knowledge of the support in the image domain. This method is suitable for general image recovery from oversampled diffuse elastic x-ray and electron-diffraction intensities. The relationship between this algorithm and the output-output algorithm is elucidated.