Print a deployment matrix of environments and regions
mediumLoops
Problem statement
A loop inside another loop, a nested loop, lets you cover every combination of two lists. For each item in the outer list, the entire inner loop runs all the way through before moving to the outer loop's next item.
flowchart TB
A["for env in environments"] --> B["for region in regions"]
B --> C["print env, region"]
C --> B
B --> A
classDef outer fill:#DBEAFE,stroke:#2563EB,color:#1E3A8A
classDef inner fill:#E0E7FF,stroke:#4F46E5,color:#312E81
classDef action fill:#D1FAE5,stroke:#059669,color:#065F46
class A outer
class B inner
class C action
Common mistake: using the same variable name for both loops.
TEXT
Wrong:for x in environments: for x in regions: print(x, x)The inner loop's x overwrites the outer loop's x, so by the time you print, both are the inner loop's value, the environment has been silently lost. Each loop needs its own name.
Your task: given environments = ["staging", "production"] and regions = ["us-east", "eu-west"], print every combination as environment - region, one per line.
Expected output:
TEXT
staging - us-eaststaging - eu-westproduction - us-eastproduction - eu-westApproach
For every environment, loop through every region, this is a plain Cartesian product, no lookup or condition involved:
environments = ["staging", "production"]
regions = ["us-east", "eu-west"]
for env in environments:
for region in regions:
print(f"{env} - {region}")