added optional 'if' filter to 'for' loop