08b_Iteration.zip

Download


Description

According to Wikipedia, "a for loop is a structured control flow statement that repeatedly runs a section of code until a condition is satisfied." As shown in the for loop pseudocode (right):

  • a is initialized to 0.
  • The 'for loop' syntax may be understood as follows:
    • The block of code within the curly braces {} is run 3 times;
    • By default, the increment i = 1.
    • For each repetition of the loop, make a = a + 1
      • First iteration 0 + 1 = 1;
      • Second iteration 1 + 1 = 2;
      • Third iteration: 2 + 1 = 3

This patcher is essentially a musical for loop. A metro object controls the pulse, or beat. Each bang received by the counter object increments the current count, which is initialized at 0 on program load. The offset (60) maps the count sequence 0, 1, 2, 3 onto the sequence 60, 61, 62, 63; i.e., it plays the pitches C4, C#4, D4, Eb4 with velocity 90 and duration 1000. By default, the counter object will repeat this process over and over. That is, until the metro object is turned off via the toggle object, this iterative process will infinitely repeat.

Further Reading

Updated: 9/23/25