Order of operation for nested 'and' blocks

My question is, when using nested and blocks to check for multiple comparisons, is every single comparison evaluated prior to the final true/false condition being evaluated? That is, if a single false value would trigger the do commands, will the do commands run as soon as that false value is registered? Or will it continue checking other conditions as well - despite them having no effect on the result.

My situation is as follows:

I have a two local tables - the first (wineList) contains a list of wines the user has on hand. The second (wines_tasted) contains a list of wines the user has tried and rated. Both tables contain the columns Vineyard, Varietal, Vintage and Series but they each also have columns not found in the other table.

I am displaying wineList using a data view and when the user initials the swipe left action it needs to check if that wine exists in the wines_tasted table, if not then it navigates to the review screen, the user submits a review, and then it returns to the screen displaying the users wine list and subtracts 1 from the number of bottles. If the user has already reviewed the wine then it just subtracts 1 from the number of bottles.

I initially put together the following to loop through the wines in the wine_tasted table and check if there was a wine where all values for vineyard, varietal, vintage and series matched. The problem is there is a good couple of second delay before this completes when running the apk on my Android phone (There are less than 10 entries in the table) - it runs almost instant on web preview. Given I am using a local data source there seems to be no way to only get a list of rows with a matching vineyard then find rows in that set with matching varietal etc. At least not without doing something more complex than what I have.

I am wondering if there is a way I can structure these comparisons so that it is more efficient without needing to build build a list of rows with matched vineyards, then search that for a list of rows with matched varietal…etc

I believe that the compiler evaluates each block in turn so I don’t think it will exit the blocks once a false value is found. You’d have to do a test or ask Thunkable staff to know for sure.

As far as your efficiency question goes, there’s probably a better way to do that. It’s helpful if you post an example of your data and the intended result for the if block. A screenshot is okay but text data is better since we can copy & paste that into a project to check it.

1 Like

I had figured that was probably the case re all blocks being evaluated in turn.

Here are two csvs of the data I am using for testing.

tastedWines example.csv (176 Bytes)H
WineList example.csv (366 Bytes)

I need to check if a row exists in tastedWines where the Vineyard, Varietal, Series and Vintage all match the wine selected from the WineList table. If it matches it will perform one action (subtract a bottle from the bottle count), if no match is found it will subtract one from the bottle count and direct the user to the review wine screen.

My current thinking is to create a list of row IDs from the tasted_wines table and create an app variable that contains a list of the Vineyard, Vintage, Varietal and Series values of the selected wine.

I can then compare the vineyards for each row in tasted wines and see if it is in the list and if it is not I remove the row ID from the app variable. That way when I go to check the varietal I only have to check the rows that had a matching vineyard. This will continue until I have either exhausted all the rows or found a match.

I feel as though thunkable is missing some crucial data related blocks for local tables. It would be nice to have some search blocks that check for multiple row values so we didn’t have to program them ourselves.

My first thought is to concatenate the properties in each row object using the ‘make text from list’ block and compare them. If you use a separator that will never appear in the database such as “#” then you can compare the two strings (the source row and each target row) to see if they are equal.

It should be faster than the current method you’re using.

I’m not sure if you can just compare the two row objects without getting their properties but that would be even quicker. There may be a row id that’s unique and included in each row object so that could be a problem.

1 Like

Ah thats actually a very good idea, should only take one trip through the dataset to confirm a match or not.

I will give it a go putting that in place.

Thanks very much for your help.

1 Like

You’re welcome! I would try comparing the object properties:

You can also assign that to a label to see the list of the properties.