issue understanding i

  • Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
i'm having difficulty comprehending the "i" in:
Code:
function bool GetNearestShop()
{
	local KFGameType KFGT;
	local int i,l;
	local float Dist,BDist;
	local ShopVolume Sp;

	KFGT = KFGameType(Level.Game);
	if( KFGT==None )
		return false;
	l = KFGT.ShopList.Length;
	for( i=0; i<l; i++ )[COLOR="Lime"]// this part mainly... what does it mean?[/COLOR]
	{
		if( !KFGT.ShopList[i].bCurrentlyOpen || KFGT.ShopList[i].BotPoint==None )
			continue;
		Dist = VSize(KFGT.ShopList[i].Location-Pawn.Location);
		if( Dist<BDist || Sp==None )
		{
			Sp = KFGT.ShopList[i];
			BDist = Dist;
		}
	}
	if( Sp==None )
		return false;
	ShoppingPath = Sp.BotPoint;
	return true;
}

... and i was wondering if someone could clear this up for me?? thankyou ahead of time :)

edit:
infact what is "for" could you point my to a tut about it or tell me what role it plays so i can look it up myslef?

from what i can gather with educated guessing is that "for" is like saying "as long as blah blah then proceede" however problem with that theory is that i could just use "if"

another theory i thought up is that "for" is like a macro so it's saying that i=0...check...i is less then I....check......add to i.... well thats my guess
 
Last edited:

9_6

FNG / Fresh Meat
Sep 4, 2009
2,461
727
0
It's a for-loop.
Handy to zip through arrays. Arrays like that shop list.
The "i" is the variable utilized by the loop. "i++" means "i=i+1", it increments i by 1 until it reaches l.
 
Last edited:

Falidell

FNG / Fresh Meat
May 22, 2009
646
78
0
33
Mesa,Az,USA
It's a for-loop.
Handy to zip through arrays. Arrays like that shop list.
The "i" is the variable utilized by the loop. "i++" means "i=i+1", it increments i by 1 until it reaches l.

ah ic ic
so you'd want the loop to continue until there is actually a shop that is open correct? no wait. ok so my logic is so:
1. access the shop index
2. run through the index cases useing the for-loop
3. continue until there is a shop that is open

ah that makes sense loops would be usefull for that.
ok thankyou very much :) and thanks for the linky link too :)
 
Last edited: