There are currently seven instructions (aka. subcommands) for the /execute command. Multiple subcommands can be chained after /execute. Subcommands are divided into 2 categories: Modifier subcommands and run subcommand.
Modifier subcommands modify execution context variables to change the context the command is executed. Subcommands following it execute with specific executor(s), execution position(s), execution dimension(s), execution rotation(s) and execution anchor.
run subcommand is used for carrying out another command.
All needed subcommands can be concatenated together. Subcommands other than the run subcommand can be arranged arbitrarily and used multiple times. But the run subcommand can be used only once and must be put at the end of the subcommands chain. A run subcommand or a condition subcommand finalizes the chain, otherwise the command is unparseable.
The game processes the subcommand chain in order from front to end, for example, the following commands are different:
All entities move one block forward: execute as @e at @s run tp ^ ^ ^1 All entities are teleported to one block in front of the executor: execute at @s as @e run tp ^ ^ ^1
Some subcommands can fork the command execution into multiple branches, that is, they cause subcommands following it to be executed multiple times. For example, when as subcommand selects multiple entities, the subcommand following it executes once per entity.
If the /execute command hasn't ever forked, we describe it as having only one branch — the main branch.
A branch may terminate halfway and does nothing (does not execute run subcommands). For example, if the condition in a condition subcommand isn't met, or as subcommand selects zero entities. If all branches terminated, we describe the /execute command itself as terminating.
Note that ... run execute ... has no effect at all. For example, the following commands work the same:
execute as @e[type=pig] as @e[type=pig] run summon pig
execute as @e[type=pig] run execute as @e[type=pig] run execute run /execute run summon pig
Better Commands' version of /execute acts like the non-coffee-flavored version of ACOVG in that it processes subcommands depth-first. This means that after forking, all the following subcommands are considered as a whole and are executed once for each branch.
There is no way to achieve breadth-first execution.
Output values
I haven't quite figured this part out yet.
Syntax
There are currently eight subcommands (eventually, there will be 12-13) for the /execute command, and each has its own special syntax, so describing syntax takes a large branching tree.
Full syntax tree
/execute ...
... align <axes> -> execute
... as <targets> -> execute
... at <targets> -> execute
... facing (<pos>|entity <targets>) -> execute
... positioned (<pos>|as <targets>) -> execute
... rotated (<rot>|as <targets>) -> execute
... run <command>
where -> execute represents the start of another subcommand that is required.
Modifier subcommands
align
Updates the execution position, aligning to its current block position (integer coordinates). Applies only along specified axes. This akin to flooring the coordinates - i.e. rounding then *downward* (not toward zero).
Any non-repeating combination of the characters 'x', 'y', and 'z'. Axes can be declared in any order, but they cannot duplicate. (For example, x, xz, zyx, or yz.)
Result
Execution position in the given axes are floored, changing by less than 1 block. Causes an error if the argument is not specified correctly.
Given (-1.8, 2.3, 5.9), execute align xz changes the position to (-2, 2.3, 5).Given (2.4, -1.1, 3.8), execute align yxz run tp @p ~ ~ ~ teleports the nearest player to (2, -2, 3).
as
Sets the executor to target entity, without changing execution position, rotation, dimension, and anchor.
Execution rotation is updated to face given position or targets.
Causes an error if the argument is not specified correctly.
Forks if <targets> selects multiple entities.
Terminates current branch if <targets> or origin: target fails to resolve to one or more entities (named players must be online).
Example
Executor rotates one degree to the left: execute facing ^1 ^ ^ run tp @s ~ ~ ~ ~ ~
All entities move one block in the direction of (0, 64, 0) (without changing their rotation): execute as @e at @s facing 0 64 0 run tp @s ^ ^ ^1
All entities move one block in the direction of (0, 64, 0) (with changing their rotation): execute as @e at @s facing 0 64 0 run tp ^ ^ ^1 ~ ~
All non player entities move one space in the direction of their nearest player (without changing their rotation): execute as @e[type=!player] at @s facing entity @p run tp @s ^ ^ ^1\
positioned
Sets the execution position, without changing execution rotation or dimension; can match an entity's position.