# Code not working when I'm breaking it up into different lines

The following code works perfectly

For[i=1,i<4,i++,Print[i]]


However, when I break this into different lines, it stops working. Moreover, the braces appear to be pink or red

For
[
i=1,i<4,i++,
Print[i]
]


Why is this happening?

• It's possible that your example could have worked under some very old versions of Mathematica, where line breaks tended to be ignored. – mikado Sep 19 '19 at 18:39

This happens because the expression

For


is complete at the location of the newline. Mathematica will not attempt to read further. Instead, it will try to interpret the next line as the start of a new expression.

Compare this with

For[


which is incomplete at the newline. Mathematica will read further to try to complete it.

Thus, use

For[
i=1, i<4, i++,
Print[i]
]