Random hack to simulate an if statement

7 views
Skip to first unread message

Marcus Brubaker

unread,
Aug 17, 2012, 6:27:38 PM8/17/12
to stan...@googlegroups.com
I know if statements are on the TODO list somewhere, but until then I thought I would share this in case it's useful to anyone else.  You can easily simulate an if statement in stan with a for loop.

For instance:

if (a > b) {
...
}

can be handled with

for  (i in 1:int_step(a-b)) {
...
}

Ugly, yes, but effective and it avoids evaluation unlike the if_then_else() function.

Cheers,
Marcus
Reply all
Reply to author
Forward
0 new messages