If I have a statement in Ruby that I want to continue on the next line, normally I would add a backslash at the end of the line like this:
print x \
+ y
But if I have comments on the line, it doesn't work:
print x #show x
+ y # show y
Is there a way around this?
(Edit: Squeegy's solution is correct and, actually, I knew you could do that but I was wondering particularly whether there is a way to have a comment on the same line as the backslash).
When it is necessary to continue to the next line, use a plus (+) or minus (-) sign as the last character of the line you want to continue. Note: If you are using REXX commands and want to continue to the next line, the plus or minus sign does not work. You must use the comma.
You cannot split a statement into multiple lines in Python by pressing Enter . Instead, use the backslash ( \ ) to indicate that a statement is continued on the next line.
If a statement does not fit on one line, enter three periods ( ... ) , also called dots, stops, or an ellipsis, at the end of the line to indicate it continues on the next line. Then press Enter or Return. Continue typing the statement on the next line.
Any sentence, entry, clause, or phrase that requires more than one line can be continued in Area B of the next line that is neither a comment line nor a blank line. The line being continued is a continued line ; the succeeding lines are continuation lines .
You need to plus sign on the first line. I dont think comments work with the blackslash
puts 'abc' + #Start abc
'def' #Add def
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