How to use logical operators for flow control