# Controlling output of graphics, the role of “;” and code structure/formatting

";" is described under Compound Expression as a delimiter, such that only the output of the last item in the compund expression is given.

Situation:

1/ Print[] produces output whether followed by ";" or not. [Clearly an override is desirable so this makes sense for compound expressions]

2/ When combining graphics using Show[], appending ";" still suppresses output. Since "Show" is as conceptually active as "Print", is there a principle at work here (are there other instances)?

3/ If in procedural code a syntactically complete line is not terminated with a ";", the following line is indented... which means Show[] in the middle of several lines of code upsets indentation and code legibility

Question: if one has several graphics that one wishes to display without combining them what is the recommended approach, given that multiple Show[] should be separated by ";" but doing so suppresses output.

PS There is an incredibly minor-but-irritating-to-the-beginner "quirk" of commenting: semi-colon before comment at the end of code before a closing "]" is marked as a syntax error - is it really? If so, what is the nature of the error (it might just be redundant)?

Block[{a},
Print[a];(*the ; preceding is magenta, but is it really a syntax error?*)]


One is tempted to say the ";" is superflous because the expression is terminated by "]", in which case why is it not still an error when extra line breaks are inserted?

Block[{a}, Print[a];
(*the ; preceding is not magenta, so why is this not a syntax error?*)
]

-
1) Print[expr] is different than expr, evaluation will send expr via Print to $Output. 2) If you have a;, b, c; in consecutive lines in the cell then only b will be printed. It is not a CompoundExpression unless you wrap it with something, e.g: (a; b c;) (each in new line) Take a look at first part of this answer too. – Kuba Mar 24 '14 at 13:57 I think the recommended way is to use Print[Show[...]]; per line. Unlike Print, Show has no side effects (at least not since the major changes in how graphics are handled in version 6). The magenta highlighting doesn't really indicate a syntax error, I'd rather consider it an error in the highlighting. If you find that highlighting irritating you could put the ; after the comment, add another ; after the comment or explicitly put Null after it. As documented a;b; is actually CompoundExpression[a,b,Null] ... – Albert Retey Mar 24 '14 at 13:58 and if your Shows are CompoundExpressions I'd do (a; Return[b, CompoundExpression]; c;), if you really can't put it in a separate line. – Kuba Mar 24 '14 at 14:05 @Kuba, thanks for the expert perspective: the documentation doesn't seem to say anything about a Compound Expression needing to be wrapped and the basic examples suggest otherwise! As for Print to Stdout - I see: I might Print to a file. Per Print documentation though, does that mean that if$Output is not Stdout then it would not "generate a cell styled print"? If so, the documentation could be clearer... – Julian Moore Mar 24 '14 at 14:10
@AlbertRetey. Hmmm... I see that as Print refers to \$Output, Show refers to \$DisplayFunction... so if Print is pointing to a file, and Show is e.g. a PopupWindow, what happens? Anyway, quirk in the highlighting it is... this beginner did spend rather too much time trying to find a synatx error though! – Julian Moore Mar 24 '14 at 14:13