|
Pages: [1]
|
 |
|
Author
|
Topic: Iterating through a block..Foreach (Read 341 times)
|
|
jfdutcher
|
<pre> A block ('blk') has been 'appended' to six times with the textual 'length' of six input boxes and looks like this: [222100] A 'foreach' loop looks like this: foreach lgth blk [ if lgth <> 2 [ alert "All input boxes need to be filled !" ] ] The alert pops up for every iteration (six times)  </pre>
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
Works for me - a test example at the console...
>> blk: [2 2 2 1 0 0] == [2 2 2 1 0 0] >> foreach lgth blk [if lgth <> 2 [probe lgth]] 1 0 0 == 0
My guess would be that your values in BLK aren't integers. Do a...
foreach lgth blk [print type? lgth]
and see what you get.
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
|
jfdutcher
|
I believe you're quite right...they must be characters in a series.
I realized I believe, that I could compare the whole block to something like "222222"...and if not equal, then an alert would be in order....without even checking the values individually. This also seemed to work.
Thanks much, John D.
|
|
|
|
|
Logged
|
|
|
|
Guest
Guest
|
I realized I believe, that I could compare the whole block to something like "222222"...and if not equal,
if block = [2 2 2 2 2 2] [print "all 2s"]
|
|
|
|
|
Logged
|
|
|
|
|
Sunanda
|
Or, if the length of the block is not fixed, and you want to know if all elements are equal to 2: myblock: copy [2 ] loop random 30 [append myblock 2]
if all [myblock/1 = 2 (next myblock) = copy/part myblock -1 + length? myblock] [ print "all 2s" ]
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |