The Alternative Csound Reference Manual
Previous |  | Next

# !=

!= -- Determines if one value is not equal to another.

## Description

Determines if one value is not equal to another.

## Syntax

(a != b ? v1 : v2)

where a, b, v1 and v2 may be expressions, but a, b not audio-rate.

## Performance

In the above conditionals, a and b are first compared. If the indicated relation is true (a greater than b, a less than b, a greater than or equal to b, a less than or equal to b, a equal to b, a not equal to b), then the conditional expression has the value of v1; if the relation is false, the expression has the value of v2. (For convenience, a sole "=" will function as "= =".)

NB.: If v1 or v2 are expressions, these will be evaluated before the conditional is determined.

In terms of binding strength, all conditional operators (i.e. the relational operators (<, etc.), and ?, and : ) are weaker than the arithmetic and logical operators (+, -, *, /, & and ||).

These are operators not opcodes. Therefore, they can be used within orchestra statements, but do not form complete statements themselves.

## Examples

Here is an example of the != opcode. It uses the files notequal.orc and notequal.sco.

Example 1. Example of the != opcode.

    /* notequal.orc */
    ; Initialize the global variables.
    sr = 44100
    kr = 44100
    ksmps = 1
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Get the 4th p-field from the score.
      k1 =  p4

      ; Is it not equal to 3? (1 = true, 0 = false)
      k2 = (p4 != 3 ? 1 : 0)

      ; Print the values of k1 and k2.
      printks "k1 = %f, k2 = %f\\n", 1, k1, k2
    endin
    /* notequal.orc */

    /* notequal.sco */
    ; Call Instrument #1 with a p4 = 2.
    i 1 0 0.5 2
    ; Call Instrument #1 with a p4 = 3.
    i 1 1 0.5 3
    ; Call Instrument #1 with a p4 = 4.
    i 1 2 0.5 4
    e
    /* notequal.sco */

Its output should include lines like this:

    k1 = 2.000000, k2 = 1.000000
    k1 = 3.000000, k2 = 0.000000
    k1 = 4.000000, k2 = 1.000000

## See Also

==, >=, >, <=, <

## Credits

Example written by Kevin Conder.

Previous | Home | Next
Orchestra Opcodes and Operators | Up | #define