Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   For Loop? (https://forums.graalonline.com/forums/showthread.php?t=134265112)

Gunderak 11-26-2011 06:28 AM

For Loop?
 
Could anyone possible explain what this does and how it is useful?
When I use it, it just returns the maximum number it can.
PHP Code:

for(temp.0temp.99 temp.++){ 


DustyPorViva 11-26-2011 07:08 AM

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;
  }



Gunderak 11-26-2011 07:16 AM

Ah ok, thanks for that.
I understand now.


All times are GMT +2. The time now is 08:27 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.