Hello world/Newline omission

From Rosetta Code
Hello world/Newline omission is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Some languages automatically insert a newline after outputting a string, unless measures are taken to prevent its output. The purpose of this task is to output the string "Goodbye, World!" preventing a trailing newline from occuring.

See also

BASIC

<lang basic>10 REM The trailing semicolon prevents a newline 20 PRINT "Goodbye World!";</lang>

C

In C, we do not get a newline unless we embed one:

<lang c>#include <stdio.h>

int main(int argc, char *argv[]) {

 (void) printf("Goodbye, World!");    /* No automatic newline */
 return EXIT_SUCCESS;

}</lang>

C++

In C++, using iostreams, portable newlines come from std::endl. Non-portable newlines may come from using constructs like \n, \r or \r\n. If we don't use any of these, we won't get a newline.

<lang cpp>#include <iostreams>

int main(int argc, char *argv[]) {

 std::cout << "Goodbyte, World!";

}</lang>

C#

<lang csharp>using System;

class Program {

   static void Main (string[] args) {
       //Using Console.WriteLine() will append a newline
       Console.WriteLine("Goodbye, World!");
       //Using Console.Write() will not append a newline
       Console.Write("Goodbye, World!");
   }

}</lang>

GUISS

In Graphical User Interface Support Script, we specify a newline, if we want one. The following will not produce a newline:

<lang GUISS>Start,Programs,Accessories,Notepad,Type:Goodbye World[pling]</lang>

Icon and Unicon

Native output in Icon and Unicon is performed via the write and writes procedures. The write procedure terminates each line with both a return and newline (for consistency across platforms). The writes procedure omits this. Additionally, the programming library has a series of printf procedures as well.

<lang Icon>procedure main()

  writes("Goodbye World!")    

end</lang>

Perl

<lang perl>print "Goodbye World!"; # A newline does not occur automatically</lang>

UNIX Shell

The behaviour of echo command is inconsistent across implementations. The -n parameter is not guaranteed to prevent a newline from occuring, so use a printf instead:

<lang sh>echo -n "Goodbye World!" # This may not work printf "Goodbye World!" # This works. newline is not automatically produced</lang>

ZX Spectrum Basic

<lang basic>10 REM The trailing semicolon prevents a newline 20 PRINT "Goodbye World!";</lang>