Dialecticus has it right: comparing computed floats for equality is dangerous. Due to some numbers not being perfectly representable in base-two (e.g., 0.1), these will only ever be approximately correct.
You can use integers as he suggests, but I'd make one further adjustment: rather than computing x[n+1] = x[n] + dx, consider computing x[n+1] = dx * i[n+1]. In other words, don't use repeated addition (which may accumulate large errors over time); instead, calculate the value of x de novo at each iteration from the integer being iterated and the floating-point step (0.1 in this case). This will not accumulate errors over time in the same way. I encourage you to try this by comparing the millionth value obtained by repeated addition vs direct multiplication at each step.
EDIT: I had a free minute so I decided to do this test myself.
<html>
<head>
<title>
Floating Point Test
</title>
</head>
<body>
<input type="button" id="btnRun" value="Run" onclick="run();" />
<br/>
<textarea id="txtOutput" rows=20 cols=50></textarea>
<script language="javascript">
function run() {
var add = 0.0;
var mul = 0.0;
var i = 0;
var dx = 0.1;
var lastPower = 1;
var output = "";
for (i = 0; i < 1000000000; i++) {
add = add + dx;
mul = dx * (i + 1);
if (i + 1 >= lastPower) {
output += "i=" + i + ", add=" + add + ", mul=" + mul + "\n";
lastPower *= 10;
}
}
document.getElementById("txtOutput").value = output;
}
</script>
</body>
</html>
The output looks like this:
i=0, add=0.1, mul=0.1
i=9, add=0.9999999999999999, mul=1
i=99, add=9.99999999999998, mul=10
i=999, add=99.9999999999986, mul=100
i=9999, add=1000.0000000001588, mul=1000
i=99999, add=10000.000000018848, mul=10000
i=999999, add=100000.00000133288, mul=100000
i=9999999, add=999999.9998389754, mul=1000000
i=99999999, add=9999999.98112945, mul=10000000
i=999999999, add=99999998.74541782, mul=100000000