Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Keyword for

Evaluate initialization once, test the middle expression before each pass, and run the update after the body. continue still runs the update, while break exits without it.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

for ($init; $condition; $update) { /* body */ }

Evaluate initialization once, test the middle expression before each pass, and run the update after the body. continue still runs the update, while break exits without it. With comma-separated conditions, only the final expression determines continuation.

$seen=[];
for($i=0,$j=3; $i<9,$j>0; ++$i,--$j){if($i===1){continue;} $seen[]=[$i,$j];}
echo json_encode($seen);
[[0,3],[2,1]]

Examples

<?php
$seen=[];
for($i=0,$j=3; $i<9,$j>0; ++$i,--$j){if($i===1){continue;} $seen[]=[$i,$j];}
echo json_encode($seen);

Result

[[0,3],[2,1]]

Sources