Dart Output
Output is what a program shows on the screen. The print command puts values on the screen as output.
Two prints on two lines
The first print ends its line before the second print starts. First and Second sit on separate lines.
void main() {
print('First');
print('Second');
}An empty line between two lines
print with an empty text value shows an empty line. A blank line sits between First and Second.
void main() {
print('First');
print('');
print('Second');
}Text and a number
The word Score sits in single quotes. The number 10 stands with no quotes and still prints.
void main() {
print('Score');
print(10);
}Example
void main() {
print('Report');
print('');
print('Pages');
print(3);
}Key points
- print is a command that shows a value and then moves to a new line.
- Each print call shows its value on its own line.
- Use print with an empty text value to show an empty line.
- A number value needs no quotes.
In this example, the first print shows Report. The second print shows an empty line. The third print shows Pages. The last print shows the number 3.
Try it Yourself
Edit the code, then press Run.
Running is simulated ยท DartPad
Exercise
Which command shows a value and then moves to a new line?