title: tensorflow: check if a scalar boolean tensor is True
body: <p>I want to control the execution of a function using a placeholder, but keep getting an error "Using a tf.Tensor as a Python bool is not allowed". Here is the code that produces this error:</p>
  
  <pre><code>import tensorflow as tf
  def foo(c):
    if c:
      print('This is true')
      #heavy code here
      return 10
    else:
      print('This is false')
      #different code here
      return 0
  
  a = tf.placeholder(tf.bool)  #placeholder for a single boolean value
  b = foo(a)
  sess = tf.InteractiveSession()
  res = sess.run(b, feed_dict = {a: True})
  sess.close()
  </code></pre>
  
  <p>I changed <code>if c</code> to <code>if c is not None</code> without luck. How can I control <code>foo</code> by turning on and off the placeholder <code>a</code> then?</p>
  
  <p>Update: as @nessuno and @nemo point out, we must use <code>tf.cond</code> instead of <code>if..else</code>. The answer to my question is to re-design my function like this:</p>
  
  <pre><code>import tensorflow as tf
  def foo(c):
    return tf.cond(c, func1, func2)
  
  a = tf.placeholder(tf.bool)  #placeholder for a single boolean value
  b = foo(a)
  sess = tf.InteractiveSession()
  res = sess.run(b, feed_dict = {a: True})
  sess.close() 
  </code></pre>