How to use DELETE EACH ?

BlitzPlus Forums/BlitzPlus Beginners Area/How to use DELETE EACH ?

GuoQiang(Posted 2005) [#1]
how to use delete each?
Thanks.


Beaker(Posted 2005) [#2]
Type thing
Field blah
End Type

Delete Each thing



sswift(Posted 2005) [#3]
Type Monster
Field Name$
Field X, Y
End Type

ThisMonster.Monster = New Monster
ThisMonster\Name$ = "Bartholemew"

ThisMonster.Monster = New Monster
ThisMonster\Name$ = "Humperdink"

For ThisMonster.Monster = Each Monster
Print ThisMonster\Name$
Next


Output:
Bartholemew
Humperdink


Delete Each Monster

For ThisMonster.Monster = Each Monster
Print ThisMonster\Name$
Next

Output:
(Nothing)


"Delete Each" simply deletes all copies of a type you have created with New.

In fact, Delete Each isn't actually a command, it is two commands. The main command is Delete. The word Each is a modifier telling Delete what to delete.

So you can:
Delete First Monster
or
Delete Last Monster
or
Delete Each Monster
or
Delete ThisMonster


sswift(Posted 2005) [#4]
Beaker:
I think my example is longer! :-)


GuoQiang(Posted 2005) [#5]
Thank you for help me.


wizzlefish(Posted 2005) [#6]
Wow - never knew about "Delete Each." :)


Grey Alien(Posted 2005) [#7]
me neither (or either as the American's say). I always did a for look with each, and called delete for every instance.


Beaker(Posted 2005) [#8]
You can even do this:
Type thing
	Field x,y
End Type

For f = 0 To 10
	th.thing = New thing
	th\x = f
Next


Delete After First thing
Delete Before Last thing


For th.thing = Each thing
	Print th\x
Next

Stop
End

ie. After First and Before Last.


Grey Alien(Posted 2005) [#9]
that's petty cool, not sure how much use it is, but it's cool