# Using AviSynth's ternary operator with multiple statements

Suppose you want to perform multiple actions based on some condition. That is, you want to do something like:

```if condition then
x = 1
y = 2
z = 3
else
x = 4
y = 5
z = 6
```

Most other programming languages provide `if`-`else` constructs that accept multiple statements. AviSynth, however, provides only the ternary operator (`?:`), which can be used only with single expressions. Therefore, the conventional way to replicate the above control structure would be to split it up:

```x = condition ? 1 : 4
y = condition ? 2 : 5
z = condition ? 3 : 6
```

There are a number of undesirable properties of this method:

• condition must be evaluated multiple times, and there are now multiple branches. In principle, this is inefficient. (Realistically, though, the performance penalty should be insignificant.)
• More importantly, this method generally is more difficult to read. It's no longer immediately obvious that the 1, 2, 3 values are grouped together, as are 4, 5, 6. Readability becomes even worse if the lines are so long that they require scrolling or that they span multiple lines.
• This method is harder to maintain. If we want to change condition, we now must modify three lines instead of one.

What can we do instead? We can (ab)use AviSynth's underappreciated `Eval` function.

`Eval("text")` feeds text back into the script parser to evaluate it, as if you had typed text by itself (with no quotes) in the script. `Eval("text")` and text are equivalent.

Consequently, if text consists of multiple lines, `Eval` will evaluate it as if multiple lines appeared in the script. This means that

```s = "x = 1
y = 2
z = 3"
Eval(s)
```

is equivalent to

```x = 1
y = 2
z = 3
```

Putting it all together, we now can see a way to replicate the structure of the original `if`-`else` example:

```s = condition ? "x = 1
y = 2
z = 3"
\             : "x = 4
y = 5
z = 6"
Eval(s)
```