I have only started learning coding recently, and am trying to grasp how for loops and while loops work. I was playing around with the following code, and was puzzled to find out that the output of the code was "hi". I thought the output of this code would have been "no" because the variable x would only continue to increase in value from 30 to 46 to 54 etc. until the parameter a is less than 1. So, I was hoping someone could point out where I went wrong with my reasoning, thank you so much!
int x = 30;
for (int a=16;a>=1;a/=2)
while((x!=14)){
x += a;
}
if (x==14){
cout << "hi" << "\n";
}
else
cout << "no" << "\n";