# Control Statements

## if … else … end if

if … else … end if

Conditional if statement

#### Examples

on controller
if (in_range($CC_NUM, 0, 127)) message("CC Number: " &$CC_NUM & " - Value: " & %CC[$CC_NUM]) else if ($CC_NUM = $VCC_PITCH_BEND) message("Pitch Bend - Value: " & %CC[$CC_NUM])
end if

if ($CC_NUM =$VCC_MONO_AT)
message("Channel Pressure - Value: " & %CC[$CC_NUM]) end if end if end on Display different text depending on various MIDI controller messages #### See Also select () ## select () select (<variable>) … case x … end select Select-case statement #### Remarks • The select statement is similar to the if statement, except that it has an arbitrary number of branches. The expression after the select keyword is evaluated and matched against individual case branches, the first case branch that matches is executed. • The case branches may consist of either a single constant number or a number range, expressed by the term "x to y"). • While there is no else or default case branch in KSP, one can be achieved by using case 08000000H to 07FFFFFFFH, which covers the whole range of 32-bit signed integer values, effectively catching all cases that don't have literally specified branches. #### Examples on controller if ($CC_NUM = $VCC_PITCH_BEND) select (%CC[$VCC_PITCH_BEND])
case -8191 to -1
message("Pitch Bend down")
case 0
message("Pitch Bend center")
case 1 to 8191
message("Pitch Bend up")
case 080000000H to 07FFFFFFH
message("We're not sure how you got this Pitch Bend value!")
end select
end if
end on

Query the state of the pitch bend wheel

if … else … end if

## while ()

while(<condition>) … end while

While loop

#### Examples

on note
ignore_event($EVENT_ID) while ($NOTE_HELD = 1)
play_note($EVENT_NOTE,$EVENT_VELOCITY, 0, $DURATION_QUARTER / 2) wait($DURATION_QUARTER)
end while
end on

Repeating held notes at the rate of one quarter note

Events and MIDI: \$NOTE_HELD
 x > y Greater than x < y Less than x >= y Greater than or equal x <= y Less than or equal x = y Equal x # y Not equal in_range(x, y, z) True if x is between (and including) y and z not a True if a is false and vice versa a and b True if a is true and b is true a or b True if a is true or b is true a xor b True only if either a or b is true, but not both
• Boolean operators are used in if and while statements, since they return if the condition is either true or false. In the list above. x, y and z denote numerals, a and b denote Boolean values.