int x = 5;
while (x == a_value){
cout << "x equals a_value;
}
as you said, this would hang the app, as it's an infinite loop.
In your second case:
1 2 3 4 5
int x;
while(x has a value){
do something;
}
it is said that x is uninitialized. That doesn't mean it has no value . It just means that you don't know its value. It's garbage, it may be 7 or 100 or probably some big number 1989381231. int x designs a lacation in memory that will be interpreted as an int. Since you don't inicialize it, what is there inside that memory location is completely unknown. But it's something.
All variables always have a value, initialized or not. You have to use another variable to remember if it was initialized, and std::optional/boost::optional does that for you.