How would i put line breaks in between lines like this:
print "Hi"
print "Hi"
Because it would just output this:
HiHi
"\n" is newline, '\n\ is literally backslash and n.
Use the backslash for Writing Multi-Line String in Ruby.
Inserting a newline code \n , \r\n into a string will result in a line break at that location. On Unix, including Mac, \n (LF) is often used, and on Windows, \r\n (CR + LF) is often used as a newline code.
In Windows and DOS, the line break code is two characters: a carriage return followed by a line feed (CR/LF). In the Unix/Linux/Mac world, the code is just the line feed character (LF).
Use puts
since it will automatically add a newline for you:
puts "Hi"
puts "Hi"
If you want to make an explicit newline character then you'll need to know what kind of system(s) on which your program will run:
print "Hi\n" # For UNIX-like systems including Mac OS X.
print "Hi\r\n" # For Windows.
Use line break character:
print "Hi\n"
print "Hi"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With