Thread: For Loop?
View Single Post
  #2  
Old 11-26-2011, 07:08 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
It repeats all the script within the loop for as many times as defined.

PHP Code:
// Initiate the variable 'temp.i' at 0
// If temp.i < 20, increase temp.i++
// for each time it needs to do this(temp.i++), it will run the 
// script inside of the loop
for(temp.0temp.20temp.++) {  
  echo(
i);

This is useful when you need to do something repetitive, like compare a single value to each element in an array.

PHP Code:
temp.val 67;
temp.arr = {2,56,23,34,6,78,67,2,34,45,67,8,23424,6,854,21};
// Create a loop the size of the array
for (temp.0temp.arr.size(); temp.i++) {
  
// compare the defined val to each element in the array
  // by using the defined temp.i(which is incremented each loop)
  // to scan through the entire array
  
if (val == arr[temp.i]) {
    echo(
"Teehee! Found you!");
    
// there's no need to keep scanning the array, so you
    // may as well stop looping, which you do via break
    
break;
  }

Reply With Quote