# If/Then Conditionals Based on a Table Column

I’ve read the documentation on tables through a couple times, and tried a couple things, but they didn’t compile. I feel like there must be a simple way to do this that I’m just not seeing.

I have a table with a column that has either 0s or 1s in it. I want to get a true result if any of the numbers in the column is 1, and a false if every single one is 0.

This is just a simplified example to clarify.

``````Table of Lights
location           status
living room          0
bathroom             1
kitchen              0
bedroom              0``````

The bathroom light is on so it would be true that at least one light is on. So if I were to have some kind of rule like:

``````After checking the lights:
if [any lights are on], say "There's a light on.";
otherwise say "All the lights are off."``````

Where the [any lights are on] would be something that would return true if there were any 1s in the Table of Lights status column.

Thanks if you can help me with this.

You might like to use truth states instead of 1’s and 0’s. But as written, the phrase you’re looking for is

`if there is a status of 1 in the Table of Lights`

It’s also the case that if you did something like

``````A room-light is a kind of device.

The kitchen light is a room-light.
The bathroom light is a room-light.
``````

then this would work directly:

`if any room-lights are switched on`

2 Likes

The example I used was just to slim down the problem for easier communication and make sure I have the syntax down before I put it to a more complex use.

Also I got an error:

Problem. You wrote ‘if there is a status of 1 in the Table of Lights’, but ‘a status of 1 in the Table of Lights’ is a value, not a reference to an entry in a table."

`if there is a <column name> of <value> in the <table name>` should work. You sure you’re using a valid column name in whatever your real table is?

Sorry I think it will actually work. I was laid low by a one letter typo in the table name.