Take the 2-minute tour ×
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.