Minor bug. (5/2. 'For' Loop Syntax)


#1

For loops in PHP 5/2

I wouldn't say I'm stuck, just a post to inform about this "bug" if it wasn't noticed allready.

The console prints correctly, but according to the task when i click Save & Submit Code, i have to use curly braces syntax ( { } ) in my for loop, even thought the PHP course earlier stated that I could use alternative syntax ( : endfor; )
This code work, but not accepted:

        for ($i = 2; $i < 11; $i = $i + 2):
          echo $i;
        endfor;

This code works and accepted:

        for ($i = 2; $i < 11; $i = $i + 2){
          echo $i;
        }

Regards
Tommy


#2

I understand where you're coming from @tommynesset95, but based on that specific exercise they wanted you to complete it in reference to the example given in the instructions. That not being as clear, you may still go ahead and report this as a bug on the lesson. But be sure to clearly state your reason. :slight_smile:


#3

Well, since PHP is a part of the older Codecademy learning environment, I believe this is the only place to report a bug. Please correct me, if I'm mistaken.

Can see that this is the same for the next few courses. If it's intended or not I cant say, but i prefer the alternative syntax so you know exactly what you are ending instead of having } } } and the end of a longer code.


#4

Yes you are correct,

It is much easier to read yes, although even with brackets you can make it significantly legible by using comments,

for example,

open { //First bracket
    if { //if bracket open
} //if bracket 1 close
else { //else bracket open 

} else bracket close

} first bracket close

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.