> For the complete documentation index, see [llms.txt](https://craftscript.kenzie.mx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://craftscript.kenzie.mx/tutorials/using-the-language/the-do-block.md).

# The Do Block

Transform the language with features from the context of an object.

## Introduction

The `do` statement is one of the most versatile and powerful syntax elements in the language. It is also one of the most complex.

In essence, it transforms the language by giving the user access to the properties of an object as new syntax keywords.

However, since the object is defined and exists only during runtime, the parse-time information and errors available are very limited, making it a trickier construct to use.

```java
do %statement% {
    
}
```

The computed object result of the statement is the target of the `do` block. All of that object's properties are unwrapped into syntax keywords.&#x20;

These keywords either reference the value of their linked property or, if the property is a function, they directly invoke that function, removing the need for the `run` statement in some contexts.

```java
do "hello" {
    assert length == 5 // "hello"[length]
    assert char_at 1 == "e" // run "hello"[char_at] 1
    assert substring 3 == "lo" // run "hello"[substring] 3
}
```

At face value this can be used as a syntax-simplifier, removing the need to write out `x[y]` property references.

However, it also allows an advanced user to alter the language with the functional properties that are available.

{% code title="Example Turtle" %}

```java
turtle = struct {
    move = fn(int) // moves int spaces
    look = fn(direction) // turns to face a direction
    north = // direction north
    east = // ...
    south = // ...
    west = // ...
    up = // ...
    down = // ...
}

do turtle {
    look north
    move 1
    look up
    move 2
    look north
    move 1
}
```

{% endcode %}

The statements in the turtle's `do` block would be completely unintelligible in regular context, but are valid syntax because they are local keywords made from the properties of the turtle object.
