updated logic.php using for loop