# Forums

Give help. Get help.

• # May 14, 2013 at 2:28 am

Hi, I m trying to get 4 sets of number which should be like this seperated in horizontal line
1 2 3 4| 5 6 7 8 | 9 10 11 12| 13 14 15 16 and I wrote a for loop for it but why does if give me an infinite loop?

< ?php
//to get four sets
for(\$i=1; \$i< =4; \$i++){ if(\$i=1){
\$n=1;
}else{
\$n= 2*\$i+1; //to increment the number
}

for(\$j=\$n; \$j< =\$n+2; \$j++){
echo \$j. ‘
‘ ;
}
echo ‘

‘; //this is hr tag but isn’t displaying on csstricks
}
?>

# May 14, 2013 at 3:29 am

OMG, such a stupid mistake, thanks for points it out.

# May 14, 2013 at 10:46 pm

Not critical here, but on a related note, I always recommend using `===` for comparison except in situations where you *specifically want* type-juggling. Example:

< ?php
\$i = 0;
// == does type coercion. FALSE and 0 are equivalent…
if( \$i == false ){ /* true! */ }
// …but NOT identical.
if( \$i === false ){ /* false! */ }

// real-world example:
\$str = “ABCDEFG”;
// you hate the letter “A”.
// make sure \$str DOES NOT HAVE the letter “A” in it!
if( strpos( \$str,”A” ) == false ){
// this compares as TRUE, even though “A” is in the string!
// this is because the *first* position in the string is position *0*.
// 0 == false.
}

// same example, but using ===
if( strpos( \$str,”A” ) === false ){
// this compares as FALSE, as expected.
// 0 !== false.
}

# May 15, 2013 at 12:47 am

learned it from javascript, where `==` is arguably useless and completely counterproductive.

# May 15, 2013 at 2:48 am

almost no one offers any explanation about how or why it’s different (especially for beginners); and it follows that there are even fewer examples in code or tutorials.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.