YU no have "for" loops?

Post » Mon Jun 18, 2012 3:24 pm

So they included "while" loops, which have the potential of easily locking up a thread by omitting an exit condition, but they left out incremental loops that, by themsleves, have a built in exit condition?

So instead of using

for int N = 1 to 10  ; Do stuff hereendfor

I have to use:

int N=0while N <= 9 do N = N + 1 ;Do Stuff Hereendwhile

How incredibly tedious!

Is there some way to add "for" statements (and maybe implementing {} blocks instead of always using an 'end(whatever)' statement? That's so Basic-Like! then the While could look like

While [CONDITION]{; Do stuff here} ; endwhile is assumed from the matching opening curly bracket
User avatar
*Chloe*
 
Posts: 3538
Joined: Fri Jul 07, 2006 4:34 am

Post » Mon Jun 18, 2012 7:13 am

it's a python style language not a C style language
User avatar
CArla HOlbert
 
Posts: 3342
Joined: Wed Feb 21, 2007 11:35 pm

Post » Mon Jun 18, 2012 12:24 pm

I could see a script extender possibly adding for loops... just have to create the syntax and have it replace it with a while loop at run time, right?

I'd also like to see foreach loops... those are fun for arrays and collections :D
User avatar
Michael Russ
 
Posts: 3380
Joined: Thu Jul 05, 2007 3:33 am

Post » Mon Jun 18, 2012 3:43 am

it's a python style language not a C style language

Monty Python maybe, with no "For" loops...

I just instinctively dislike loops with iterators that can be modified within the loop (or that you can accidentally forget to change, or change in the wrong direction, etc..)
User avatar
Liv Staff
 
Posts: 3473
Joined: Wed Oct 25, 2006 10:51 pm

Post » Mon Jun 18, 2012 12:44 pm

it's a python style language not a C style language
I thought Python had for loops similar to what OP mentioned?

C-style for loops go like this:
for (int i = 0; i < x; ++i) // x is any number{  // Do stuff here}
User avatar
Elea Rossi
 
Posts: 3554
Joined: Tue Mar 27, 2007 1:39 am

Post » Mon Jun 18, 2012 5:24 pm

And the excuse "We don't need for loops because we can do the same thing with a while loop" is like saying "We don't need the abiltiy to type "LOL" because we can do the same thing by typing "I am laughing out loud" - but don't hold your breath for "LOL" to disappear, mon!
User avatar
Esther Fernandez
 
Posts: 3415
Joined: Wed Sep 27, 2006 11:52 am

Post » Mon Jun 18, 2012 4:41 pm

I could see a script extender possibly adding for loops... just have to create the syntax and have it replace it with a while loop at run time, right?

I'd also like to see foreach loops... those are fun for arrays and collections :biggrin:

I usually just make a linked list structure (already started working on one just this morning, like so)

; Papyrus Tool: Linked Lists - a definition that implements everything you need to create and use doublly-linked lists in Papyrus.; More intuitive than Nextref, etc. Simply have the data structure extend LinkedList and give your listed items references to the objects or data you need.; Added LinkedList Functionality: Find and Random LinkedList Functions to locate the N'th item in a list, or grab a random item from the list.Scriptname LinkedList extends FormLinkedList Next = None auto; Reference variable to the "Next" item in a linked list.LinkedList Prev = None auto; Reference variable to the "Previous" item in a linked list.LinkedList First = None auto; Reference variable to the "Header" item in a linked list.LinkedList Function Count(LinkedList List) globalif List  LinkedList CounterReference = List.First ; Start at the beginning.  int countme=1  while CounterReference.Next   countme = countme + 1   CounterReference = CounterReference.Next  endwhile  return countendifreturn 0 as int ; was passed a None referenceendfunctionLinkedList Function FindListItem(LinkedList List, int N) globalLinkedList Finder = List.Firstint X=1while X < N  x = X + 1  if Finder.Next   Finder = Finder.Next  endifendwhilereturn FinderendfunctionLinkedList Function RandomListItem(LinkedList List) globalint X = Utility.RandomInt(1, Count(List)); Random number between 1 and Count(List)LinkedList Which = FindListItem(List,X)return WhichendFunctionLinkedList Function UpdateFirst(LinkedList List, LinkedList NewFirst) global ; Goes through list, and changes the "First" references to NewFirst.if List  LinkedList Check = List  while Check   Check.First = NewFirst   Check = Check.Next  endwhileendifendFunctionLinkedList Function BumpFirst(LinkedList List) global ; Makes the first item in a multi item list the second item. Returns a reference to the old second item (or None in single item lists)LinkedList FirstItem = List.First ; When passing by reference, avoid assigning directly to the passed variable.if FirstItem.Next ; Make sure we're dealing with a multi item list  FirstItem.UpdateFirst(FirstItem,FirstItem.Next) ; Update the "First" references.  if FirstItem.Next.Next ; If there is a third item to be linked to   FirstItem.Next = FirstItem.Next.Next  endif  FirstItem.Next.Prev = None  return FirstItem.First ; Returns a reference to the first item in the re-ordered list.endifreturn None ; Was a single item listendFunctionLinkedList Function Move(LinkedList This, LinkedList FromList, LinkedList ToList) global ; Moves item "This" from list "FromList" to list "ToList"if This  if FromList; First, take "This" out of "FromList" robustly so the "FromList" list maintains it's integrity.    if This.First == FromList.First ; Ensures that "This" is actually IN "FromList" to begin with.	 if This.Next ; if "This" is not at the end of it's list, bypass "This" going forward.	  This.Next.Prev = This.Prev	 endif	 if This.Prev ; If "This" is not at the start of it's list, Bypass "This" going backward.	  This.Prev.Next = This.Next	 endif	 if This = FromList.First; Special Case! Need to update FromList reference to next item as well as move item!	  FromList = BumpFirst(FromList); "FromList" list will now start with second item (or is None if it was last item); Officially changes the "FromList" reference by assigning directly to it. We won't be using it again here.	 endif    else	 return ; Do nothing. "This" wasn't in "FromList" at all.    endif   This.Next = None   This.Prev = None   This.First = This ; "This" is temporarily in a list by itself!   if ToList ; Next, Add "This" to list "ToList"    This.First = ToList.First    if ToList.Next ; If there is a next element to link to	 ToList.Next.Prev = This	 This.Next = ToList.Next    endif    ToList.Next = This    This.Prev = ToList    return   endif ; If there was no "ToList" list to start with, be sure to assign the reference "ToList" to be "This"   ToList = This  endifendif endFunctionLinkedList Function Add(LinkedList Item, LinkedList List) global; Adds Item to List. Not recommended for use to move items from one list to another, as you may lose your reference!if Item ; Make sure we were passed an item.  if Item.First ; If Item is already in a list   if Item.First == List.First    return ; Hey, you can't fool me! It's already IN that list!   endif   Item.Move(Item,Item.First,List); You really don't want to do this, but it's here anyway. Hope you maintained an additional reference to the list Item is in.   return  endif  if List   Item.Next = List.First.Next ; First, link to the First items' "next" link.   if List.First.Next    List.First.Next.Prev = Item    Item.Next = List.First.Next   endif   List.First.Next = Item   Item.Prev = List.First   Item.First = List.First   return  endif  List = Item ; List was empty, but not anymore.  Item.Next = None  Item.Prev = None  Item.First = ItemendifendFunction

(Warning: Unfinished Code. Probably won't work yet!)
User avatar
Amy Masters
 
Posts: 3277
Joined: Thu Jun 22, 2006 10:26 am

Post » Mon Jun 18, 2012 4:31 am

I thought Python had for loops similar to what OP mentioned?

C-style for loops go like this:
for (int i = 0; i < x; ++i) // x is any number{  // Do stuff here}
i was referring to how the OP wanted scripts to use { and } at the bottom of his post
User avatar
Jack
 
Posts: 3483
Joined: Sat Oct 20, 2007 8:08 am

Post » Mon Jun 18, 2012 5:39 pm

i was referring to how the OP wanted scripts to use { and } at the bottom of his post
Ohhh. My bad.
User avatar
Krystina Proietti
 
Posts: 3388
Joined: Sat Dec 23, 2006 9:02 pm


Return to V - Skyrim