-2

I tried to create a while loop.

<div>
    <?php
        while($i < 100){
            echo $i + 100
            $i++;

            if($i = 23){
                echo 'reached!';
            }
        }
    ?>
</div>

But I just get errors. What did i make wrong?

Thank you!

dsfsdf
  • 13
  • 1
  • 2
    When posting a question asking about errors its always a good idea to include the errors in the post. – Jite Oct 18 '15 at 12:47
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Barif Oct 18 '15 at 12:50
  • There's a difference between = and ==. And you're using the wrong one – Reeno Oct 18 '15 at 14:03

2 Answers2

1

Thats not hard to fix.

You can get the mistake from the errors.

  1. you forgot a ";" after the echo $i + 100

  2. if ($i = 23) have to be if($i == 23)

So finaly it looks like:

<?php
     while($i < 100){
         echo $i + 100;
         $i++;

         if($i == 23){
             echo 'reached!';
         }
     }
 ?>
Marion Piloo
  • 63
  • 10
0

Try to add ; after echo $i + 100 :

echo $i + 100;
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Scream
  • 100
  • 3
  • 11