title: How could I make this variable assignment function into a loop?
body: <p>I've notated where it repeats. A variable goes into the function, and based on parts of its value, it's routed through this function. However, the same thing needs to repeat with different variables, same otherwise... a lot of times.</p>
  <p>Is there a slicker way to do this? I couldn't figure it out with a for loop.</p>
  <pre><code>    case _ where message.addressParts[0] == &quot;GigPerformer&quot; :
          if message.addressParts[1] == &quot;Main&quot;{
              if message.addressParts[2] == &quot;Voice&quot;{
                  if message.addressParts[3] == &quot;CurrentSongName&quot;{
                      gpMainVoice.gpSongNumber = &quot;\(message.arguments.first ?? error)&quot;
                      gpMainVoice.gpSongName = &quot;\(message.arguments.last ?? error)&quot;
                  }
                  if message.addressParts[3] == &quot;CurrentSongPartName&quot;{
                      gpMainVoice.gpCurrentSongPartNumber = &quot;\(message.arguments.first ?? error)&quot;
                      gpMainVoice.gpCurrentSongPartName = &quot;\(message.arguments.last ?? error)&quot;
                  }
                  if message.addressParts[3] == &quot;SongPartName&quot;{
                          for i in gpMainVoice.gpSongPartNumber.indices {
                              if &quot;\(message.arguments.first ?? error)&quot; == String(i) {
                                  gpMainVoice.gpSongPartNumber[i] = &quot;\(message.arguments.first ?? error)&quot;
                                  gpMainVoice.gpSongPartName[i] = &quot;\(message.arguments.last ?? error)&quot;
                              break
                          }
                      }
                  }
              }
  </code></pre>
  <p>//                Here's where it repeats</p>
  <pre><code>        if message.addressParts[2] == &quot;Amp&quot;{
              if message.addressParts[3] == &quot;CurrentSongName&quot;{
                  gpMainAmp.gpSongNumber = &quot;\(message.arguments.first ?? error)&quot;
                  gpMainAmp.gpSongName = &quot;\(message.arguments.last ?? error)&quot;
              }
              if message.addressParts[3] == &quot;CurrentSongPartName&quot;{
                  gpMainAmp.gpCurrentSongPartNumber = &quot;\(message.arguments.first ?? error)&quot;
                  gpMainAmp.gpCurrentSongPartName = &quot;\(message.arguments.last ?? error)&quot;
              }
              if message.addressParts[3] == &quot;SongPartName&quot;{
                      for i in gpMainAmp.gpSongPartNumber.indices {
                          if &quot;\(message.arguments.first ?? error)&quot; == String(i) {
                              gpMainAmp.gpSongPartNumber[i] = &quot;\(message.arguments.first ?? error)&quot;
                              gpMainAmp.gpSongPartName[i] = &quot;\(message.arguments.last ?? error)&quot;
                          break
                      }
                  }
              }
          }
      }
  </code></pre>