fixed for statement upper bound
Added tests with sample code