read, readln


Purpose
Read in formatted data from the active input stream.
Synopsis
procedure read(e1:expr[, e2:expr...])
procedure readln
procedure readln(e1:expr[, e2:expr...])
Argument
e1, e2,... 
Expression or list of expressions of basic type
Example
The following reads (possible split over several lines) 12 45 word, followed by toto(12 and 45)=word:
declarations
 i,j:integer
 s:string
 ts:array (range,range) of string
end-declarations
read(i, j, s) 
readln("toto(", i, "and", j, ")=", ts(i,j))
Further information
1. These procedures assign the data read from the active input stream to the given symbols or try to match the given expressions with what is read from the input stream. If ei is a symbol that can be assigned a value, the procedure tries to recognise from the input stream a constant of the required type and, if successful, assigns the resulting value to ei. If ei is a constant or a symbol that cannot be reassigned, the procedure tries to read in a constant of the required value and succeeds if the resulting value corresponds to ei. These procedures do not fail but set the control parameter nbread to the number of items actually recognized.
2. Note that the read procedures are based on the lexical analyser of Mosel: items are separated by spaces and a string that contains spaces must be quoted using either single or double quotes (the quotes are automatically removed once the string has been identified).
3. The procedure readln expects all the items to be recognized to be contained in single line. The function read ignores changes of line. If the procedure readln is used without parameters it skips the end of the current line.
Related topics
write, write.


If you have any comments or suggestions about these pages, please send mail to docs@dashoptimization.com.