Print the given expression or expressionlist. e.g.
print 'My name is Cobra.'
Lacking any 'to DEST' clause the expressions provided are printed to the standard output with a trailing line terminator (\n or \r\n depending on platform).
This trailing line terminator may be suppressed with a terminating 'stop' token after the expression list. ( There is no ',' before this token)
print 'No newline' stop
Multiple comma separated expressions are printed each separated by a single space.
print 'No moa', 'No moa', 'in all aotearoa' # emits 'No moa No moa in all aotearoa\n'
If a 'to DEST' clause is given the expression list is printed to that destination which must be a TextWriter or subclass.
The final form of the print statement given below does not print anything but sets up a (TextWriter or subclass) redirection destination for any print statements in the subsequent block.
Any and all of string expression interpolation and String.format processing can be specified within the expressions of the expression list.
Grammar
print print [to DEST,] <expression> [, expression ...] [ stop] print to DEST BLOCK
Platform
.Net: the destination must be a System.IO.TextWriter or subclass.
Examples
print # emit a blank line print 'Hello World'
print 'Prompt:' stop input = Console.readline print a,b,c stop print d # a b c d all end up on the same line
print "one", '2', 'free' # emits 'one 2 free\n' i = 2 s = 'free' print 'one [i] [s]' # same output as above
# print to std error print to Console.error, 'error: all froobits bedazzled' sw = StringWriter() print to sw print 'Redirected to the StringWriter' s = sw.toString assert s.contains('Redirected to the StringWriter')
Notes
Non string expressions are converted to a string representation for printing (presumably using their toString methods).
Collections are expanded so their contents are displayed using CobraCore.PrintStringMaker.makeString (++ This needs expansion/explanation ++ )
See discussion forum Print vs Console.Writeline