switch statement - If...else if...else in REBOL -
I've found that a has not been created in REBOL ... if ... altif ... and < / Code> syntax, like this:
theVar: 60 {This will not work} if theVar & gt; 60 [Print "Greater than 60 Greater!" ] Elsf theVar == 3 [Print "It's 3!" ] Elsf Thyvir & lt; 3 [Print "This is less than 3!" ] And [print "this is something else!" ] I have found an alternative solution, but it is very important:
thevar: 60 or thevar> 60 [Print "Greater than 60 Greater!" ] [Either verse == 3 [print "it's 3!" ] [Either Ver & lt; 3 [Print "This is less than 3!" ] [Print "It's Something else!" <]> Is there a more concise way to implement a ... and if ... and chain in the rebole?
The construct you look for will be CASE. This situation and code takes a series of blocks, to evaluate, only evaluates the blocks if the situation is correct and to stop after the first true situation is completed.
theVar: 60 case [thevar> 60 [Print "Greater than 60 Greater!" ] TheVar == 3 [Print "It's 3!" ] Thevar & lt; 3 [Print "This is less than 3!" ] True [print "This is something else!" As you see, getting the default is not that easy to attack a real situation.
Apart from this: If you want, you can be in all cases run / case / short circuit with everyone, this matter prevents the first condition from stopping; It will run them in sequence, evaluate any block for any real situation.
Comments
Post a Comment