goto

goto — Transfer control on every pass.

Description

Transfer control to label on every pass. (Combination of igoto and kgoto)

Syntax

goto label

where label is in the same instrument block and is not an expression.

[Note] Note
Using goto not as part of an if statement (as in: goto end), will cause initialization to be skipped on all the code the goto jumps over. In performance, leaving some opcodes uninitialized will cause deletion of the note/event. In these cases, using kgoto (as in: kgoto end) might be preferred."

Examples

Here is an example of the goto opcode. It uses the file goto.csd.

Example 430. Example of the goto opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o goto.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1.
instr 1
  a1 oscil 10000, 440, 1
  goto playit

  ; The goto will go to the playit label.
  ; It will skip any code in between like this comment.

playit:
  out a1
endin


</CsInstruments>
<CsScore>

; Table #1: a simple sine wave.
f 1 0 32768 10 1

; Play Instrument #1 for one second.
i 1 0 1
e


</CsScore>
</CsoundSynthesizer>


See also

Program Flow Control

Credits

Example written by Kevin Conder.

Added a note by Jim Aikin.