S
S
Senseich2018-04-07 23:31:53
PHP
Senseich, 2018-04-07 23:31:53

Why does just a PHP script hang?

Hello! I'm doing a simple task in PHP, but I don't understand why everything freezes. Or I learned by heart and do not see some details, tell me)

<p>Выводим сумму четных чисел от 10 до 40</p>
<?php 

$summ = 0;
$num = 10;

while($num <= 40){
    
    if(($num%2) != 0) continue;
    $summ += $num;
    $num++;
}

echo $summ;

 ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman PHP, 2018-04-07
@Senseich

continue is used inside loop structures to skip the rest of the current loop iteration and, if conditions are met, start the next iteration.
11 is always less than 40, so the loop will be infinite

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question