Immediately after the for keyword, there must be an unindexed variable. Immediately after that there must be an equal sign, =
After that,there are a few different possibilities:
- You can have an expression then a colon and then another expression, such as for k = 1:10
- You can have an expression then a colon then another expression then a colon and then a third expression, such as for k = 1:2:9
- You can have a general expression that computes a scalar or vector or array result, such as for k = sqrt(x.^2+y.^2)
None of the valid syntaxes include the possibility of a ~= at that point.
In the above list of possibilities, the third one involves fully evaluating the expression and recording all of the values for later use. The first and the second look very much the same, and act very much the same: it is as if the values were all recorded at the time the for statement is encountered. The difference between the first two and the third, is that in practice MATLAB special-cases the : and :: variations and does not fully evaluate the expression to the right. For example MATLAB can deal with for k = 1 : inf without having to generate the infinite list of values 1, 2, 3, and so on, and store them all for later use -- whereas the third option, any expression other than : or :: expression, fully evaluates and records before starting the loop.