Introduction Welcome Getting Started My First Program     Troubleshooting and Distributing Transforming Data Interactive Programs     Programming Exercises     Making Games
Documentation Declarations     Procedures     Variables Statements     Flow Control Expressions Libraries     Print     IO     Random     Game Engine
Tutorials Complete Tutorials     Introduction to Programming     Quick Start     Programming Exercises     Programming Games

STATEMENTS


All About Statement in Vizzcode





What are Statements?

Statements are actions (or commands) with which you build your program.
Statements could be assignments, procedure calls, flow control statements, etc.

For example, inside a block, there can be declarations and statements:
main
:: () {
    a :=
5
;
    a =
6
;
    
if
(a <
10
) {
        b :=
10
;
        a =
b
;
    }
}

In the Visual Panel, statements are the nodes connected by the execution line - the white one:

Which nodes are statements in the example program

Learning about the statements you have at your disposal to build your program with and how they work is very important to gain more expressive power when programming.
In the next section, you will see all the statements in the Vizzcode language.




Kinds of Statements

Here are the statements available in Vizzcode: (you can access more information on each one by accessing their documentation section)




Assignments

A very common statement is an assignment.
It simply assigns a value to a variable. An assignment is made using a single equals = symbol.
In the following example, inside the main procedure, a variable is declared and then the value 10 is assigned to it.
main
:: () {
    var :
int
;
    var =
10
;
}

The next section shows these statements in visual nodes.

It's also common to refer to an assignment as setting the value of a variable.

You can assign values to variables in their declarations like so:

main
:: () {
    var1 :=
5
;
    var2 :=
"Hello, all!\n"
;
}

There are special assignment statements that operate on the value and assign the result to the variable.
There are 5 special assigns: add and assign, subtract and assign, multiply and assign, divide and assign and mod and assign.
main
:: () {
    var1 :=
10
;
    var1 +=
2
;
    
if
var1 ==
12
 
print
(
"True"
);
}

This is the equivalent of:
main
:: () {
    var1 :=
10
;
    var1 = var1 +
2
;
    
if
var1 ==
12
 
print
(
"True"
);
}

Here is all of them in action:
main
:: () {
    var :=
5
;
    var =
10
;
    var +=
5
;
    var -=
2
;
    var *=
10
;
    var /=
5
;
}

Try printing the value of the variable before and after each assignment to make sure you know what value it will contain.




Node Assignment

Assignments work in the Visual Panel just like in the Text Panel.
You case use the Assign node to set a value to a variable, like so:

How to set the value of a variable in Vizzcode

In the first slot of the node, you connect a variable (or any assignable expression) and in the second one you connect any expression that resolves to the variable's type:

What nodes should be connected to the Assign Node

Just like with any other expression you can type the expression in the textbox just like you would do in the Text Panel:

Typing expressions inside the node's textboxes

Besides the basic assignment node, there are 5 special nodes that also operate on the value before assigning:

The special assignment nodes

That is the equivalent of the following operation and assignment:

How does the special assignment nodes (add and assign) work





Return

The return statement is used to exit the current procedure.
It's also used to return values from procedures.

This is its basic use: (Note that the second print will not be called because the procedure will exit before it)

#import
"Print"


main
:: () {
    
print
(
"This will run."
);
    
return
;
    
print
(
"This will not."
);
}

And the equivalent in Visual Nodes:

How does the return statement work

In the case of returning values from procedures, you can simply enter an expression after the return keyword:
proc
:: () ->
int
{
    
return
10
;
}

Returning values with the return statement

Another example:
multiple
:: () -> first :=
5
, second :=
10
, third :
string
{
    
return
second =
5
, third =
"Hello!"
;
}

Returning named values