Nested ForEach() in PowerShell

Viewed 74861

I'm having some troubles with nested ForEach loops in Powershell. First, I need to iterate through list 1. For every object in list 1, I need to iterate through list 2. When I found the resembling object in list 2, I want to go to the next object in list 1.

I've tried break, i've tried continue, but it won't work for me.

Function checkLists() {
  ForEach ($objectA in $listA) {
    ForEach ($objectB in $listB) {
       if ($objectA -eq $objectB) {
           // Do something 
           // goto next object in list A and find the next equal object
       }
    }
  }
}

a) What does a break/continue exactly do in PowerShell?

b) How exaclty should I conquer my 'problem'?

4 Answers
Related