<p>The statements are not on the stack, they're in the script. They start immediately after the <code>OP_IF</code>. They end at the first <code>OP_ELSE</code> or <code>OP_ENDIF</code>, assuming there isn't a nested <code>OP_IF</code> or <code>OP_NOTIF</code>. So it looks like this</p>

<pre><code>// script to put a number on the stack
OP_IF
// script that runs only if the number isn't zero
OP_ENDIF
// script that runs no matter what
</code></pre>

<p>or:</p>

<pre><code>// script to put a number on the stack
OP_IF
// script that runs only if the number isn't zero
OP_ELSE
// script that runs only if the number is zero
OP_ENDIF
// script that runs no matter what
</code></pre>

<p>You can read a bit more about in <a href="http://web.archive.org/web/20120118072127/http://bitcoinstats.com/irc/logs/2011/01/13/14#l168035" rel="noreferrer">this chat transcript</a>.</p>

CC BY-SA 3.0
2011-12-27T01:34:27.560Z
2013-02-26T21:01:13.963Z
2013-02-26T21:01:13.963Z
David Schwartz
<p>Description of the OP IF is a bit vague on the wiki. Where does one get statements for the op for? Are they coming from the stack, or from somewhere else? Are there any available examples of how a script using that op code looks like?</p>

<development><protocol><script>
Script - OP_IF etc. clarifications
ThePiachu
# Script - OP_IF etc. clarifications

(Asked by: username_0 on 2011-12-27)

Description of the OP IF is a bit vague on the wiki. Where does one get statements for the op for? Are they coming from the stack, or from somewhere else? Are there any available examples of how a script using that op code looks like?

**Tags:** development, protocol, script


---

## 1 answers

### Answer by username_1 on 2011-12-27. Score: 10 | Accepted answer

The statements are not on the stack, they're in the script. They start immediately after the `OP_IF`. They end at the first `OP_ELSE` or `OP_ENDIF`, assuming there isn't a nested `OP_IF` or `OP_NOTIF`. So it looks like this

```
// script to put a number on the stack
OP_IF
// script that runs only if the number isn't zero
OP_ENDIF
// script that runs no matter what

```

or:

```
// script to put a number on the stack
OP_IF
// script that runs only if the number isn't zero
OP_ELSE
// script that runs only if the number is zero
OP_ENDIF
// script that runs no matter what

```

You can read a bit more about in [this chat transcript](http://web.archive.org/web/20120118072127/http://bitcoinstats.com/irc/logs/2011/01/13/14#l168035).


---

