Difference between print() and println()
An easy way to see the difference is using Serial.print();
/Serial.println();
.
print();
will print out whatever you input wherever the cursor currently is. For example:
Serial.print("Test");
Serial.print("Words");
This will print:
TestWords_
The underscore marks where the cursor is (and therefore where the next print command will start). In contrast, the code:
Serial.println("Test");
Serial.println("Words");
will print the following:
Test
Words
_
You can also print multiple statements and then follow with println
like so (note the space at the end/beginning of the strings):
Serial.print("These ");
Serial.print("Test");
Serial.println(" Words.");
to get the following output:
These Test Words.
_
You can also use println();
to add a newline character in general. If you would print a variable that doesn't return a newline character, println();
can be used for formatting. Example:
int x = 50;
Serial.print(x);
Serial.println();
This will print:
50
_
Finally, you can add in special characters like a tab \t
inside your quotes for formatting. Example:
Serial.println("Test\tTest")
This will return:
Test Test
_
print() prints whatever you send in.
println() does the same thing, only after using println, anything new that is printed gets printed in next line, I.e. a new line is formed.