ext_119979 ([identity profile] foradan.livejournal.com) wrote in [personal profile] purplecat 2007-08-04 09:03 am (UTC)

I don't know about Java. Here is some python:

for x in list_of_things:
if all(b.test_belief(x) for b in list_of_formulae):
do_something_with(x)
break # if you only are looking for the first matching x

Hmmm, I don't know Java very well but doesn't it have the 'break' and 'continue' statements from C?
If you have an outer loop over things and an inner one over formulae, then 'break' out of the inner one
if a test returns false. After the inner loop, check if the last test was false or true, if false, then 'continue'
to the next x.

Ah, reading your description, it looks like you have the outer loop over the tests and the inner loop over the things? Is that neccessary? If so you need to keep a list of things that have passed all the tests so far, which, for each test, you go through and remove those that fail the test. At the end you are left with a list of all the things that have passed all the tests. Java must have lists, doesn't it?

Post a comment in response:

This account has disabled anonymous posting.
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org