Back propagation algorithm with a for-loop implementation