Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Iterating through a block..Foreach
Pages: [1] Print
Author Topic: Iterating through a block..Foreach  (Read 341 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Iterating through a block..Foreach
« on: July 16, 2004, 08:17:06 AM »

<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)  Huh
</pre>   
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Iterating through a block..Foreach
« Reply #1 on: July 16, 2004, 09:32:21 PM »

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
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Iterating through a block..Foreach
« Reply #2 on: July 20, 2004, 10:35:11 AM »

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


Email
Iterating through a block..Foreach
« Reply #3 on: July 23, 2004, 05:12:40 AM »

Quote
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
Full Member
***
Offline Offline

Posts: 109


View Profile
Iterating through a block..Foreach
« Reply #4 on: July 23, 2004, 01:57:36 PM »

Or, if the length of the block is not fixed, and you want to know if all elements are equal to 2:

Code:
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] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Iterating through a block..Foreach
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 10:06:21 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2287 Posts in 596 Topics by 3717 Members
Latest Member: oraximmoxia

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc