Getting Started With V Programming Pdf Updated Info
git clone https://github.com/vlang/learn
cd learn/docs
pandoc getting_started.md -o v_getting_started.pdf --latex-engine=xelatex
(Install pandoc and a LaTeX engine first.)
Once you have V installed, it's time to write your first program. Here’s a classic "Hello, World!" example:
fn main()
println('Hello, World!')
Let’s go through this:
To run this program, save it in a file named hello.v, then execute it using the V compiler:
v run hello.v
You should see "Hello, World!" printed in your terminal. getting started with v programming pdf updated
Before diving into the "how," let’s understand the "why." V was created by Alexander Medvednikov with a clear manifesto:
A: The official Discord server (discord.gg/vlang) is extremely active. Also, the GitHub Discussions board.
V does not use classes. Instead, it uses structs for data encapsulation.
V only has one loop keyword: for.
1. The C-style for:
for i := 0; i < 5; i++
println(i)
2. The for in loop (arrays/maps):
nums := [1, 2, 3]
for num in nums
println(num)
3. The while equivalent:
mut count := 0
for count < 5
println(count)
count++
4. Infinite loop:
for
// Do something forever
// Use 'break' to exit
As you become more comfortable with the basics, you'll want to explore more advanced topics. Here are some steps you can take:
Functions are defined using the fn keyword. V enforces that function arguments are immutable by default.
fn add(a int, b int) int
return a + b
fn main()
result := add(5, 7)
println(result) // Output: 12
To modify arguments inside a function, they must be marked with mut.
fn increment(mut n int)
n++
fn main()
mut count := 5
increment(mut count)
println(count) // Output: 6