Hello, World Program is a basic Simple First program or application. To learn any new language, You have to learn how to write the first program

It just displays the hello world string to the console.

This post shows how to write a hello world application in Nim Programming language.

Nim Hello World example program

Following are steps to create a Hello World program in Nim programming language

  • First, Open any source code editor
  • Create a file called HelloWorld.nim
  • Add the following code
  ## Hello World Sample First Program
  echo('Hello World First Program');
}

The above program contains three parts.

Comments : The comments are ignored by the compiler and provide a useful message about the line or block of a code.

 # Hello World Sample First Program

It contains the echo function.

  • echo: It is used to print the string or a message to the console. It is a standalone IO function.

The valid echo statement is

echo "hello world";

The below echo statement gives compilation error /usercode/in.nim(1, 8) Error: missing closing ' for character literal

echo 'hello world';

How to Compile and run Nim program

We can compile and run the program in many ways in Nim programming.

In this, Let’s see how to compile and run the program using the terminal.

nim command is available on command with installation,

  • Command-line

    • Open terminal command line.

    • Go to the directory or folder where the program exists.

    • run the below command(nim c HelloWorld.nim)

      A:\work\nim>nim c HelloWorld.nim
      

      argument c is an alias for compile option. This output HelloWorld binary file in the current directory.

      Run Nim program with below command

      A:\work\nim>HelloWorld
    

    Output

    Hello World First Program
    

    You can compile and run the Nim program with a single command

    nim c -r --verbosity:0 HelloWorld.nim
    

    c: is an alias for compile option -r: is an –run option –verbosity:0 It restricts and displays only required message

  • online Nim Playground online browser

    • open Nim Playground in the browser

    • Type the HelloWorld code or copy it

    • Click on the Run button (Ctrl + Enter) on the opened pad.

    • you will see the Hello World First Program message in the Console window.

    • Source Code Editor or IDE

  • you can open any editor of your choice such as VSCode

  • Install Extension Nim

  • Run inbuilt compiler support or open terminal and run as per command line