TL ; DR:
The console is a panel that displays important messages, like errors, for developers.
In Rust, we use
println!to print something to the console. For example, this program:println!("{}", 13);
prints
13to the console.
Full lesson:
The console is a panel that displays important messages, like errors, for developers.
Much of the work the computer does with our code is invisible to us by default. If we want to see things appear on our screen, we can print to our console directly.
println!:
In Rust, we use println! to print something to the console. For example, this program:
println!("{}", 13);
prints 13 to the console.
When you run this program, this is what you'll see in your console:
13
We refer to the data printed to the console as the output of the program.
End of line:
In Rust, println! automatically adds a newline at the end of whatever it prints.
This newline moves the cursor to the next line in the console. It's like pressing Enter in your text editor to move to the next line.
We usually use println! when we want to print multiple values on separate lines:
println!("{}", 1);
println!("{}", 2);
println!("{}", 3);
The ouput of this program would be:
1
2
3
Assignment
Follow the Coding Tutorial and let's print some values to the console!
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. Premium is unlimited.