Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-26-2011, 06:28 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.++){ 
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #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
  #3  
Old 11-26-2011, 07:16 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Ah ok, thanks for that.
I understand now.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:04 AM.


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