Explaining what this line does is easy enough: it checks if
C is even by dividing it by 2 and comparing the result to its floor, then stores the result of the comparison in the variable
T. Comparisons are expressions like any other: they return a non-zero value (in the Applesoft dialect, 1) if the relation holds and zero otherwise. The
IF statement evaluates an expression, and if it returns non-zero, executes the statement given after the
THEN keyword. The line can thus be re-written like this:
T = (C/2 = INT(C/2))
T = 0 : IF C/2 = INT(C/2) THEN T = 1
and remain functionally the same.
Interestingly (as @another-dave points out), it was not always a feature of BASIC that relational operators could appear in any expression. The original Dartmouth BASIC did not allow it: the fourth edition manual (1968) defines a ‘formula’ to contain arithmetic operations only (§1.2, pp. 11–15), while an
IF statement could perform a single comparison between two such ‘formulas’ (§1.2, p. 15; §1.7.5, p. 35). There were no logical connectives like
NOT either. Dartmouth BASIC also included simultaneous assignment to multiple variables in a single statement:
LET A = B = 2 would assign 2 to both
B (§1.7.1, p. 33).
One of the earliest BASIC dialects that unified relational and arithmetic expressions was HP Time-Shared BASIC (1976). Doing so introduced a grammar ambiguity with multiple assignment, resolved in the manual as follows (‘LET Statement’, p. 11-46):
The rule that the equal sign (“=”) is an assignment operator only holds as long as numeric variables occur in the replacement list. If a numeric constant appears, followed by an equal sign, that equal sign is treated as a relational operator. For example, in A=2=B the first “equal sign” (=) is treated as an assignment operator and the second is treated as a relational operator.
(Presumably parentheses would also do the trick.)
Apple’s Integer BASIC (1977) followed suit in unifying arithmetic and relational expressions (pp. 56–58 in the manual), though it omitted multiple assignment. Microsoft dialects (1975) did similarly, though in the latter truth was usually represented as −1; this allowed logical connectives to perform double duty as bitwise operators. In those dialects, the ambiguity is instead resolved by the strict dichotomy between statements and expressions: if an
= appears in statement position, it means assignment, while in expression position it refers to comparison. As lone expressions are not statements, unlike for example in C, the meaning of
= is unambiguous.
=symbols are parsed differently: the first as assignment and the second as equality test. Here, C would have used
==for the latter.
Y = (x > 7) * 10will set Y to 0 or 10 based on the value of X. You can do a similar thing in C, though you have to be careful with older implementations.
=operator does mean that you can't use some constructs popular in other programming language like multiple assignment (
a = b = 0) or assignments as part of loop conditions (
while ((c = f()) >= 0)), but these can be easily worked around.