Hello world/Newline omission

From Rosetta Code
Task
Hello world/Newline omission
You are encouraged to solve this task according to the task description, using any language you may know.

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 << "Goodbye, 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>

Euphoria

<lang euphoria>-- In Euphoria puts() does not insert a newline character after outputting a string puts(1,"Goodbye, world!")</lang>

gecho

<lang gecho>'Hello, <> 'world! print</lang>

Go

<lang go>package main

import "fmt"

func main() { fmt.Print("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>

Haskell

<lang haskell>main = putStr "Goodbye, world"</lang>

Objeck

<lang objeck> bundle Default {

 class SayHello {
   function : Main(args : String[]) ~ Nil {
     "Hello World!"->Print();
   }
 }

} </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>

Java

<lang java>public class HelloWorld {

public static void main(String[] args)
{
 System.out.print("Goodbye, World!");
}

}</lang>

Liberty BASIC

A trailing semicolon prevents a newline <lang lb>print "Goodbye, World!"; </lang>


ML/I

Simple solution

In ML/I, if there isn't a newline in the input, there won't be one in the output; so a simple solution is this (although it's hard to see that there isn't a newline). <lang ML/I>Goodbye, World!</lang>

More sophisticated solution

To make it clearer, we can define an ML/I skip to delete itself and an immediately following newline. <lang ML/I>MCSKIP " WITH " NL Goodbye, World!""</lang>

OCaml

In OCaml, the function print_endline prints a string followed by a newline character on the standard output and flush the standard output. And the function print_string just prints a string with nothing additional.

<lang ocaml>print_string "Goodbye, World!"</lang>

PARI/GP

<lang parigp>print1("Goodbye, World!")</lang>

PASM

<lang pasm>print "Goodbye World!" # Newlines do not occur unless we embed them end</lang>

Perl

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

Perl 6

A newline is not added automatically to print or printf <lang perl6>print "Goodbye, World!"; printf "%s", "Goodbye, World!";</lang>

PicoLisp

<lang PicoLisp>(prin "Goodbye, world")</lang>

PureBasic

<lang PureBasic>OpenConsole() Print("Goodbye, World!") Input() ;wait for enter key to be pressed</lang>

Python

<lang python>import sys sys.stdout.write("Goodbye, World!")</lang>

Works with: Python version 3.x

<lang python>print("Goodbye, World!", end="")</lang>

Retro

<lang Retro>"Goodbye, World!" puts</lang>

Ruby

<lang ruby>print "Goodbye, World!"</lang>

Scheme

<lang scheme>(display "Goodbye, World!")</lang>

Seed7

<lang seed7>$ include "seed7_05.s7i";

const proc: main is func

 begin
   write("Goodbye, World!");
 end func;</lang>

Standard ML

<lang sml>print "Goodbye, World!"</lang>

Tcl

<lang tcl>puts -nonewline "Goodbye, World!"</lang>

UNIX Shell

The echo command is not portable, and echo -n is not guaranteed to prevent a newline from occuring. With the original Bourne Shell, echo -n "Goodbye, World!" prints -n Goodbye, World! with a newline. So use a printf instead.

Works with: Bourne Shell

<lang bash>printf "Goodbye, World!" # This works. There is no newline. printf %s "-hyphens and % signs" # Use %s with arbitrary strings.</lang>

The print command, from the Korn Shell, would have worked well. Too bad, because most shells have no print command. With pdksh, the built-in print command might run faster than the external printf utility, because it avoids a fork.

Works with: pdksh

<lang bash>print -n "Goodbye, World!" print -nr -- "-hyphens and \backslashes"</lang>

C Shell

C Shell does support echo -n and omits the newline.

<lang csh>echo -n "Goodbye, World!" echo -n "-hyphens and \backslashes"</lang>

ZX Spectrum Basic

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