if Instrument Control:Program Flow Control if if Branches conditionally at initialization or during performance time. Description if...igoto -- conditional branch at initialization time, depending on the truth value of the logical expression ia R ib. The branch is taken only if the result is true. if...kgoto -- conditional branch during performance time, depending on the truth value of the logical expression ka R kb. The branch is taken only if the result is true. if...goto -- combination of the above. Condition tested on every pass. if...then -- allows the ability to specify conditional if/else/endif blocks. All if...then blocks must end with an endif statement. elseif and else statements are optional. Any number of elseif statements are allowed. Only one else statement may occur and it must be the last conditional statement before the endif statement. Nested if...then blocks are allowed. Note Note that if the condition uses a k-rate variable (for instance, if kval > 0), the if...goto or if...then statement will be ignored during the i-time pass. This allows for opcode initialization, even if the k-rate variable has already been assigned an appropriate value by an earlier init statement. Syntax if ia R ib igoto label if ka R kb kgoto label if xa R xb goto label if xa R xb then where label is in the same instrument block and is not an expression, and where R is one of the Relational operators (<, =, <=, ==, !=) (and = for convenience, see also under Conditional Values). If goto or then is used instead of kgoto or igoto, the behavior is determined by the type being compared. If the comparison used k-type variables, kgoto is used and viceversa. If/then/goto statements cannot do audio-type comparisons. You cannot put a-type variables in the comparison expressions for these opcodes. The reason for this is that audio variables are actually vectors, which cannot be compared in the same way as scalars. If you need to compare individua audio samples, use kr = 1 or Comparators Examples Here is an example of the if...igoto combination. It uses the file igoto.csd. Example of the if...igoto combination. See the sections Real-time Audio and Command Line Flags for more information on using command line flags. Its output should include lines like this: instr 1: iparam = 0.000 instr 1: ifreq = 440.000 instr 1: iparam = 1.000 instr 1: ifreq = 880.000 Here is an example of the if...kgoto combination. It uses the file kgoto.csd. Example of the if...kgoto combination. Its output should include lines like this: kval = 0.000000, kfreq = 440.000000 kval = 0.999732, kfreq = 440.000000 kval = 1.999639, kfreq = 880.000000 Examples Here is an example of the if...then combo. It uses the file ifthen.csd. Example of the if...then combo. See also Program Flow Control Credits Examples written by &namekevin;. Added a note by Jim Aikin. February 2004. Added a note by &namematt;.