Print and echo
Echo
Echo displays an expression, or a list of expressions separated by commas,
without blank space (as the print statement does).
Syntax:
echo expression [, expression]
There is no blank space between expression nor line feed at end. To add a
line feed, use "`\n".
The string inside double quotes " " displayed by the echo or print
command is send as is to the target language, Php or C++.
If the $ symbol is present, for the Php interpreter, this denotes a variable
included into the string and the content of the variable is displayed, not
the name nor the $ sign. The {} curly brace symbols also have a special meaning.
A string inside simple quotes ' ' is displayed as is by the Php interpreter,
the $ sign is displayed as a $.
But inside a C++ program, these symbols have no meaning and are displayed
as is.
Examples of echo commands: | int
x = 5 int y = 20 int z = 1 echo "values:", x, y / 2 echo z echo '\n" `line feed echo "score: $x" |
Displays: | >
values:5101 > score: 5 |
The print comman display a text as echo, but:
- each comma inserts a blank space,
- a line feed is added to the end of the text.
Syntax:
print expression [, expression]
A print statement with expression puts just a line feed.
Examples of print commands: | int
x = 5 int y = 20 int z = 1 print "values:", x, y / 2 print z |
Displays: | >
values: 5 10 > 1 > |
Take note that in Php, print and echo are all converted into "echo" statement, but with formatting in the case of print.
Scriptol
|
Php
|
print print "demo", 5 echo "demo", 5 |
echo "\n"; echo "demo", " ", 5, "\n"; echo "demo", 5; |
Exercises |
1) In the goal of obtening this table: |