Hello World

  1. fn main() {
  2. println('hello world')
  3. }

Save this snippet into a file named hello.v. Now do: v run hello.v.

That is assuming you have symlinked your V with v symlink, as described here. If you haven’t yet, you have to type the path to V manually.

Congratulations - you just wrote and executed your first V program!

You can compile a program without execution with v hello.v. See v help for all supported commands.

From the example above, you can see that functions are declared with the fn keyword. The return type is specified after the function name. In this case main doesn’t return anything, so there is no return type.

As in many other languages (such as C, Go, and Rust), main is the entry point of your program.

println is one of the few built-in functions. It prints the value passed to it to standard output.

fn main() declaration can be skipped in one file programs. This is useful when writing small programs, “scripts”, or just learning the language. For brevity, fn main() will be skipped in this tutorial.

This means that a “hello world” program in V is as simple as

  1. println('hello world')