Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: fun with for loops

From: lmecir:mbox:vol:cz at: 2-Aug-2002 23:04

Hi Charles, if I understood correctly, you would like to have: set-words: function [ {Get all set-words from a block} block [block!] ] [elem words] [ words: make block! length? block parse block [ any [ set elem set-word! ( insert tail words to word! :elem ) | skip ] ] words ] cfor: function [ {a C-like for function} [throw] init [block!] test [block!] inc [block!] body [block!] ] [use-words cont] [ use-words: append set-words init [continue] body: append reduce [:catch body] inc cont: reduce [does [throw none]] use use-words reduce [ :set [continue] cont :do init :while test body ] ] Usage: cfor [i: 1] [i <= 3] [i: i + 1] [ if i = 2 [continue] print i ] 1 3 -L ----- Original Message ----- From: "Charles" Howdy folks. Got a bit of a difficulty here. Say I'm evaluating a for loop, like reading lines of text from a file. At the beginning of my for loop, I have it check to see if the line is commented, blank, or neither. If it's commented or blank, I want it to just skip to the next iteration of the for loop; however, if it's neither, let it keep going. I would prefer to do this with a simple if [] as opposed to a heavy either [][]... 'break' doesn't do what I need - it kills the for loop entirely, instead of skipping to the next iteration. If I use either [][], I have to do: either condition? [ if true do this ][ if false do these next 20 lines all indented with more indentation yet to come very long lines ] You follow me? It's a coding habit I've picked up from another language. Thanks folks. --Charles