I tried a this simple for loop using both a double and a float and I am getting different results and I don't know why
for (double i = 0; i < 1; i += 0.1) cout << i << endl;
for that I get the following output 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 and I do not understand why 1 is being an output when it should clearly break the for loop condition. However when I change the type from double to float like so:
for (float i = 0; i < 1; i += 0.1) cout << i << endl;
then I get the following output as I would expect 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
And in this case, I do not get 1 as an output since when i=1 it will break the loop condition. I cannot understand what is going on, I have run this in Visual Studio several times with the same result.