An infinite loop runs forever because the condition never becomes false. This happens when you forget to update the loop variable. Example: int i = 0; while (i < 5) { cout << i; } never increments i, so i stays 0 and the condition is always true.
Your program hangs. To fix infinite loops, verify that the loop body changes variables used in the condition. Every loop needs progress toward the exit condition.