CKTIS / PHP
Keyword do
Execute a loop body before testing its condition, guaranteeing one pass unless control transfers out earlier.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
do { /* body */ } while ($condition);Execute a loop body before testing its condition, guaranteeing one pass unless control transfers out earlier. The condition controls repetition, not the initial entry. The terminating semicolon after while is part of this syntax.
$attempt=0; $seen=[];
do { $seen[]=++$attempt; } while ($attempt<0);
echo json_encode($seen);
[1]
Examples
<?php
$attempt=0; $seen=[];
do { $seen[]=++$attempt; } while ($attempt<0);
echo json_encode($seen);
Result
[1]