Jskid Posted April 22, 2010 Share Posted April 22, 2010 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? Link to comment https://forums.phpfreaks.com/topic/199440-is-there-a-keyword-to-make-a-variable-not-change/ Share on other sites More sharing options...
andrewgauger Posted April 23, 2010 Share Posted April 23, 2010 http://php.net/manual/en/function.define.php Link to comment https://forums.phpfreaks.com/topic/199440-is-there-a-keyword-to-make-a-variable-not-change/#findComment-1046751 Share on other sites More sharing options...
trq Posted April 23, 2010 Share Posted April 23, 2010 if your condition never changes your loop will either never start or never end. Link to comment https://forums.phpfreaks.com/topic/199440-is-there-a-keyword-to-make-a-variable-not-change/#findComment-1046780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.