Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: While ... break
Pages: [1] Print
Author Topic: While ... break  (Read 1636 times)
John
Guest


Email
While ... break
« on: October 21, 2005, 09:16:17 AM »

People hi,
I really need some help.

Can you give me a small example of a while loop using a break
I'm trying this:
Code:

num: [20 30 40 50 60 70 80]

while [not tail? num] [
  print first num
  num: next num
  if num = 60 [break]
]


..but it does not break at 60, the loops prints all values
please help me, where is the error
i want to use while, not for.. or other loop

thank you !

Logged
bouba
Newbie
*
Offline Offline

Posts: 10


View Profile
While ... break
« Reply #1 on: October 21, 2005, 09:24:04 AM »

be careful, num is a series!

so it is not
Code:
if num = 60 [break]
but
Code:
if 60 = first num [break]

you could have also written :
Code:
foreach val num [
   print val
   if val = 60 [break]
]
which I find simpler. ;)
« Last Edit: October 21, 2005, 09:25:42 AM by bouba » Logged
John
Guest


Email
While ... break
« Reply #2 on: October 21, 2005, 12:11:38 PM »

thank you very much  Tongue  
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
While ... break
« Reply #3 on: October 22, 2005, 04:11:56 PM »

An alternative to...
Code:
if 60 = first num [break]
is...
Code:
if num/1 = 60 [break]
« Last Edit: October 22, 2005, 04:12:17 PM by CarlRead » Logged

- Carl Read
John
Guest


Email
While ... break
« Reply #4 on: October 23, 2005, 06:11:28 AM »

Thanks Carl, i got it now.


Also i have a problem, i'm trying to run this script taken form Rebol's web site 'How to' section

Code:
view/new layout [

   the-box: box "A Box" forest feel [
       engage: func [face action event] [
           print [action event/key]
       ]
   ]
]
focus the-box
do-events

It says that 'When you type on the keyboard you will see a stream such as:

key a
key b
key c
key d

It's not working on me, every time i run the script, the console crashes !!
Any suggestions ?

I'm using REBOL/View 1.3
Thanks again people.
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
While ... break
« Reply #5 on: October 23, 2005, 07:11:56 AM »

That snippet works fine here.
Logged
John
Guest


Email
While ... break
« Reply #6 on: October 26, 2005, 04:12:04 PM »

I don't know why it's not working on me.

One more question.
I'm having a bit of touble with remove and insert, i'm confused.

In a string like this:

str: "Reboloton"

how to use remove function to remove 't' only and make a new str string: "Reboloon"

And same to insert, how to insert one more 't' and make the string "Rebolotton"

What's the fastest way, can you give me an example?

Thanks again friends.

:rolleyes:  
Logged
Guest
Guest


Email
While ... break
« Reply #7 on: October 27, 2005, 11:28:54 AM »

ok, i found it i used remove/part at str x x

Tongue

sorry for the silly questions i'm newbie to rebol



Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
While ... break
« Reply #8 on: October 28, 2005, 01:19:55 AM »

Quote
It says that 'When you type on the keyboard you will see a stream such as:

key a
key b
key c
key d

It's not working on me, every time i run the script, the console crashes !!
Any suggestions ?

I'm using REBOL/View 1.3
Thanks again people.
It works for me too.  What OS are you running REBOL on?
« Last Edit: October 28, 2005, 01:20:52 AM by CarlRead » Logged

- Carl Read
John
Guest


Email
While ... break
« Reply #9 on: October 28, 2005, 04:20:46 AM »

Windows XP without any SP
Rebol system version 1.3.1.3.1 (without install)

Every time i run the script it opens a window 'A Box'
But i cant close it, and i cant type anything to console even if i press 'esc'

Sad
Logged
Sunanda
Full Member
***
Offline Offline

Posts: 113


View Profile
While ... break
« Reply #10 on: October 28, 2005, 08:46:39 AM »

John -- have your tried clicking the "a box" -- that's what starts the demo.

After that, you should be able to press keys (etc) and see the result in the REBOL console window.

You can close the window by hitting ESCape in the REBOL console window and then:
 unview/all
Logged
John
Guest


Email
While ... break
« Reply #11 on: November 04, 2005, 12:19:49 PM »

Sunanda thanks for your answer. No i cant find a solution, console halts..

This is 2 small scripts i made.
Nothing special, i will rewrite them when i learn Rebol  :lol:
The first gives 10 unique random numbers (1 - 10)
Code:
;create unique random numbers
numbers: func [] [
num: copy [1 2 3 4 5 6 7 8 9 10]
temp: copy []

loop 10 [
 r: random (length? num)
 v: pick num r
 append temp v
 r: r - 1
 num: skip num r
 remove num
 num: head num
]
print temp
]

copy-paste and type 'numbers'

>> numbers
5 8 4 7 3 2 1 6 10 9



The second is a string permutation function
It finds all letters combinations from a string

Code:
;string permutation
substr: func [string start length][
       copy/part at string start length
   ]

perm: func [string1 string2] [
either (length? string2) = 1 [
  print join string1 string2
  ] [
    for i 1 (length? string2) 1 [
    string2_first_character: pick string2 1
    string3: join string1 string2_first_character
    string4: substr string2 2 (length? string2)
    perm string3 string4

    string2_first_character: pick string2 1
    remove string2
    append string2 string2_first_character
  ]
]
]
Type perm "" "REBOL"

>> perm "" "REBOL"

REBOL
REBLO
REOLB
REOBL
RELBO
RELOB
RBOLE
...




Also i have a question, i realy need your help people
 I make an object with the name of box
 It has a 'state' variable.

Code:
box: make object! [
 state: none
 ]

Now this simple loop below prints ob1 ob2 ob3 ob4 ob5 ..

Code:
repeat x 10 [
str: copy "ob"
append str x
print str
]

My question is how can i make a new box clone with the name of str value 'obx'
And then i can check its value, like this 'print ob4/state'
My English are poor, hope you understand
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
While ... break
« Reply #12 on: November 05, 2005, 04:04:05 AM »

Did you try:

Code:
>> random [1 2 3 4 5 6 7 8 9 10]
== [5 8 6 2 7 1 3 4 10 9]

? Wink
Logged
John
Guest


Email
While ... break
« Reply #13 on: November 05, 2005, 05:12:58 AM »

WOW  :lol:
thank you Gabriele, no i did not try that !
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: While ... break
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 08:14:46 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2315 Posts in 597 Topics by 4203 Members
Latest Member: fn2000 assault rifle

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

RT design by Defiant Pc