Meta Project

The Unofficial Meta Documentation

ANY

Summary

ANY is the Meta way of using a disjunction, the Boolean OR operator in other languages.

Category

LOGIC CONTROLS

Usage

ANY block

Arguments

ANY takes a BLOCK! of conditions as argument

Refinements

This method has no refinements

Description

ANY is the Meta way of using a disjunction, the Boolean OR operator in other languages. The return value of ANY is most thought of a being a LOGIC!, a TRUE or FALSE value. But this is not entirely the case. ANY checks all conditions within the BLOCK! to be satisfied, the first value that is not none or false will be returned. The use of ANY is chosen over OR because this frees up OR for BITWISE operations. ANY is a very versatile method.

ANY can also be used as a program control without the use of for example IF.

Example Code

ANY [ high-score?
      moves < 100 ][ code to perform here]

ANY can be used as a switch or case statement and to prevent a nested if structure. Instead of writing:

either condition-1 [
    code-1
][
    either condition-2 [
        code-2
    ][
        either condition-3 [
        ][
           ...
        ]
    ]
]

You can write:

any [
    if condition-1 [
        code-1
        true ; in case code-1 returns FALSE or NONE
    ]
    if condition-2 [
        code-2
    ]
    ...
    (default-code)
]

You can even squeeze some default code to perform in there in case no condition was met.

Related

ALL  
NOT  

Back to the Meta Methods Reference index