How to work with the symbol EndOfFile? I want to use the EndOfFile symbol to determine when my control structure reaches the end of a file.
Case 1: suppose we reach the end of file while continuously reading numbers from it. Which correctly returns "end".
num=EndOfFile;
Which[
num==EndOfFile, res="end",
num==1, res="1",
num==2, res="2",
True, res="non"
]
(* ==> "end" *)
Case 2: suppose we read a 3 (that is, num=3): in this case Which returns unevaluated.
SameQ(===) to test for structural identity instead of numerical equation (Equal===).EndOfFiledoes not have a numerical value thus ifnumis 1,1 == EndOfFilereturns unevaluated. – István Zachar Feb 27 '13 at 03:21