# Locally Defined Values

**This tutorial covers:**

- Let expressions
- Nested let expressions

**Before starting, you should be familiar with:**

**At the end, you should be able to:**

- Illustrate what let and nested let expressions are
- Write a let and nested let expression
- Express how let and nested let expressions work

In the values tutorial we learned how to create values that we can use in our BoGL programs. Whereas normal values can be used throughout multiple parts of your program, a locally defined value can only be used in a single specified expression. This is useful if you know that a value is only needed for a single expression, or if you want to break an existing expression up into something more concise. In BoGL, we can create locally defined values by using *let expressions*.

You can write a let expression by first writing the keyword `let`

followed by the desired name of the value (must start with a lowercase letter), followed by an equals sign `=`

. After the equals sign is where the expression of the locally defined value is defined. After this expression you must write the keyword `in`

, followed by the expression that the locally defined value will be used in.

In the example above, we are using the locally defined value `x`

in the expression `x / 5 + x`

. The expression in this example could also be written on a new line after the keyword `in`

.

This kind of change can often increase the readability of our program, especially when it comes to writing more complicated expressions.

## Nested Let Expressions

The ending expression of a let expression can be another let expression. A let expression that uses a value that was defined in an earlier let expression is called a *nested let expression*. Nested let expressions can be useful if we want to define several values to use in an expression. Shown below is an example of this.

The defining expression of a local value in the let expression will always be evaluated before the expression which uses the local value (which is the expression that comes after the `in`

keyword). Below is an example that illustrates this.

Shown below is a math equation that evaluates in an order that is identical to the program above.

**x = (((1 + 1) * 2) + 3) * 4**