READ IT COMPLETELY

well... the question is very basic...but i am much confused. what is the difference between Serial.println and Serial.print example for this program.. serial monitor shows I LOVE YOU and in the next line BUT NO SEX, i agree void setup() { Serial.begin(9600); Serial.println("I LOVE YOU"); Serial.print("BUT NO SEX"); }

void loop() {

} but when i am typing this in void loop() like

void setup() {Serial.begin(9600); } void loop() { Serial.begin(9600); Serial.println("I LOVE YOU"); Serial.print("BUT NO SEX"); }

now this time monitor shows like BUT NO SEXI LOVE YOU(continously) PROBLEM is monitor is supposed to show I LOVE YOU BUT NO SEX. why the order is being changed?

Serial.println() adds a linefeed after whatever is printed. Serial.print() doesn't.

UKHeliBob: Serial.println() adds a linefeed after whatever is printed. Serial.print() doesn't.

Which you could have figured out in 10 seconds by looking at the man page.

You should also read the two posts at the top of this Forum by Nick Gammon on how to post to this Forum, especially the use of code tags when posting source code. You should also use Ctrl-T to reformat your code in the IDE before you post it.

It's doing exactly what it is supposed to. It prints "I LOVE YOU" and a new line. Then "BUT NO SEX" with no new line. Then the loop function repeats, so it prints "I LOVE YOU" again. And since there was no new line after "BUT NO SEX" it is going to be put right after it on the same line.

void setup()
{Serial.begin(9600);
}
void loop()
{
Serial.println(“I LOVE YOU”);
Serial.print(“BUT NO SEX”);
delay(2000);
}

if you put a delay in

you should see " I love you" came first (line feed = move to the next line)

and then but no sex (no line feed = stay on the same line) + I love you ( then moved the next line and went on and on

you have no delay in your code and it is happening so fast

actually I love you has been printed at the very top

THANKS for such a wonderful explanation. :)