|
Pages: [1]
|
 |
|
Author
|
Topic: While ... break (Read 1639 times)
|
John
Guest
|
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: 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
|
be careful, num is a series! so it is not if num = 60 [break]
but if 60 = first num [break]
you could have also written : 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
|
thank you very much
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
An alternative to... if 60 = first num [break] is... if num/1 = 60 [break]
|
|
|
|
« Last Edit: October 22, 2005, 04:12:17 PM by CarlRead »
|
Logged
|
- Carl Read
|
|
|
John
Guest
|
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 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
|
That snippet works fine here.
|
|
|
|
|
Logged
|
|
|
|
John
Guest
|
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
|
ok, i found it i used remove/part at str x x sorry for the silly questions i'm newbie to rebol
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
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
|
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'
|
|
|
|
|
Logged
|
|
|
|
|
Sunanda
|
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
|
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) ;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 ;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. box: make object! [ state: none ]
Now this simple loop below prints ob1 ob2 ob3 ob4 ob5 .. 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
|
Did you try: >> random [1 2 3 4 5 6 7 8 9 10] == [5 8 6 2 7 1 3 4 10 9]
?
|
|
|
|
|
Logged
|
|
|
|
John
Guest
|
WOW :lol: thank you Gabriele, no i did not try that !
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2315 Posts in 597 Topics by 4205 Members
Latest Member: TimTearton
|