I was writing a small console application in Delphi (XE), and by mistake wrote:
for I := 0to aList.Count-1 do
Note the missing space between “0” and “to”
I didn’t notice this until after I had run the program, and I was surprised the compiler accepted this. It’s probably no big deal, but it made me curious.
Why does Delphi accept this typo?
It’s for the same reason that you don’t need spaces around the
.or the-. Since atcan never come after an initial0in any recognisable token, the lexical analyser simply returns the0as an integer-literal token, and then recognises thetoas a distinct keyword token. If you had made a different mistake instead —for I := 0 to10— you’d now have a problem, sinceto10is recognised as a valid identifier, which is illegal immediately after the0.