Jump to content

is there a keyword to make a variable not change?


Jskid

Recommended Posts

Say I wanted to do a loop and the condition never changes. How can I make it so that the condition doesn't get recalculated each time?

 

For example

$myString = 'hello world';//I'm not going to reassign anything to this variable

for($i = 1; i<=strlen($myString); i++)

{

...

}

 

$people = 342;//not going to change

for($j = 0; j<sqrt($people); j++)

{

...

}

[/php}

I could calculate it outside the loop and save it in a variable and it would be good for readability if there's a statment to help people know that the variables not going to change. Or is there a completely different method?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.