Var And Var! In Microsoft Bosque Programming Language
All programming languages have one central area that is used to declare the variables. In this article, we are going to learn how to declare a variable in Bosque programming.
- var
- var!
- var statement is used to declare a const variable
- var! is used to declare a non-const variable.
var variable
- var Identifier = exp;
- var identifier : Datatype = exp;
The example declaration code is given below.
- var x:Int = 3; // variable declare as int and initialized.
- var x =” Hello World”; // variable introduced and inferred to be of type string
Once a variable has initialized, it can't be changed at a later point. In the below sample code, a variable is initialized as “Hello World” and is later changed to “Welcome Bosque.”
- namespace NSMain;
- entrypoint
- function main(): String {
- var x2 = "Hello World";
- x2 = "Welcome bosque";
- return x2;
- }
Compile the program. The Bosque compiler throws a parse error “variable defined as const.”

var! variable
In the case of var! the syntax can be modified by assignment statements. We can declare the var! variable in three different types. Two types are the same as var declaration while the third one is only a datatype declaration without initialization.
- var !identifier: Type;
- var !Identifier = exp;
- var !identifier: Datatype = exp;
Below is the sample code using var!
- namespace NSMain;
- entrypoint
- function main(): String {
- var !x2 = "Hello World";
- x2 = "Welcome bosque";
- return x2;
- }
var! must define the datatype or should be initialized otherwise compiler throws an error. In the below code, we have declared only a variable without defining the datatype or without initialization.
- namespace NSMain;
- entrypoint
- function main(): String {
- var !x;
- return x;
- }
Compile the program. The Bosque compiler throws an error.

var and var! assignment
The below code shows that var! only is declared not assigned any value and it is assigned to var variable “x”.
- namespace NSMain;
- entrypoint
- function main(): String {
- var !x: String;
- var x1 = x;
- return x;
- }
Compile the program. It throws an error.

Before assigning to var x1 = x, initialize the x variable, then it will work out.
- namespace NSMain;
- entrypoint
- function main(): String {
- var !x: String;
- x = "Difference between var and var!";
- var x1 = x;
- return x1;
- }
Run the program.

Conclusion
Happy Coding!!!

Sarathlal SaseendranPosted May 18, 2019, 3:12 PM
Something different and interesting Vinoth. Thanks for sharing.
Mahesh ChandPosted May 18, 2019, 7:17 AM
Nice Vinod. You may want to put links to your previous article for someone who finds this article. Cheers!