Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with V Programming

You're reading from   Getting Started with V Programming An end-to-end guide to adopting the V language from basic variables and modules to advanced concurrency

Arrow left icon
Product type Paperback
Published in Dec 2021
Publisher Packt
ISBN-13 9781839213434
Length 408 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Navule Pavan Kumar Rao Navule Pavan Kumar Rao
Author Profile Icon Navule Pavan Kumar Rao
Navule Pavan Kumar Rao
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Section 1: Introduction to the V Programming Language
2. Chapter 1: Introduction to V Programming FREE CHAPTER 3. Chapter 2: Installing V Programming 4. Section 2: Basics of V Programming
5. Chapter 3: Variables, Constants, and Code Comments 6. Chapter 4: Primitive Data Types 7. Chapter 5: Arrays and Maps 8. Chapter 6: Conditionals and Iterative Statements 9. Chapter 7: Functions 10. Chapter 8: Structs 11. Chapter 9: Modules 12. Section 3: Advanced Concepts in V Programming
13. Chapter 10: Concurrency 14. Chapter 11: Channels – An Advanced Concurrency Pattern 15. Chapter 12: Testing 16. Chapter 13: Introduction to JSON and ORM 17. Chapter 14: Building a Microservice 18. Other Books You May Enjoy

Introducing functions

Functions allow you to logically wrap a set of instructions inside a code block to perform a specific operation. Often, it is necessary to provide them with a name that represents the underlying logic they encompass. Functions might take arguments as an input to perform an operation. Additionally, they might return the result of the operation performed by it. Therefore, functions offer code reusability and code readability.

A function can call another function if required to do so. In some scenarios, a function can call itself to perform a recursive operation.

V facilitates working with functions. A function in V is created using the fn keyword. The typical syntax to create a function in V is shown here:

ACCESS-MODIFIER fn FUNCTION_NAME(ARGUMENT1_NAME ARGUMENT1_DATATYPE, ARGUMENT2_NAME ARGUMENT2_DATATYPE) RETURN_DATATYPE {
    OPERATIONS
}

In the preceding syntax, we can identify two parts of a function:

  • A method signature...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime