The following PHP code is working as expected. I need to echo “copy error” message when the code is unable to execute the command in 4 attempts.
for($num_tries = 0 ; $num_tries < 4 ; $num_tries++)
{
$cloudcmd = "cp abc xyz ";
system($cloudcmd,$status);
if($status != 0)
{
sleep(3) ;
continue ;
}
break ;
}
I tried to add echo command after break; but it does not seem to work.
Strictly, you don’t need to introduce additional variables and checks to do this.
Keeping it simple, you can inspect the value of the for loop variable $num_tries once outside the for loop:
You also have the $status variable available after the for loop.