# PRE: if foreach
#
#  Redundant blocks.
#
#  The first one fails, so the second one is used
#
uint32 count

count := 0;
request += {
	NAS-Port = 0
	NAS-Port = 1
	NAS-Port = 2
	NAS-Port = 3
	NAS-Port = 4
	NAS-Port = 5
	NAS-Port = 6
	NAS-Port = 7
	NAS-Port = 8
	NAS-Port = 9
}

#
#  Loop 0..9
#
foreach NAS-Port {
	redundant-load-balance {
		group {
			# fail on even numbered values, succeed on odd numbered ones
			if (%{Foreach-Variable-0} % 2 == 0) {
				fail
			}
			else {
				count += 1
				request += {
					Reply-Message = "Succeed odd %{Foreach-Variable-0} %{count}"
				}
				ok
			}
		}
		group {
			# succeed on even-numbered values, fail on off-numbered ones.
			if (%{Foreach-Variable-0} % 2 == 1) {
				fail
			}
			else {
				count += 1
				request += {
					Reply-Message = "Succeed even %{Foreach-Variable-0} %{count}"
				}
				ok
			}
		}
	}
}

if (!(count == %{NAS-Port[#]})) {
	test_fail
}

success
