Skip to content
Advertisement

How to make tables with X amount of booleans with all possible values?

How do i iterate through all possible X boolean values? i.e i have 2 booleans, how do i make a table with all truths and falses?

like:

  • A 0 0 1 1
  • B 0 1 0 1

Advertisement

Answer

Try to iterate over the 2 ** number of variables integers. The following example for 4 variables:

JavaScript

will produce the following:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement