I think this is what you are looking for, the first solution was a short cut.
int cities ={{20,30,40},{2,4,5},{7,3,5},{6,11,17}};
int distances ={ };
int distance ={ };
function setup(){
createCanvas(400,400);
background(100)
for ( i = 0; i< cities.length; i++) {
for (j = 0; j < cities[i].length-1; j++) {
distances = ((cities[i][j]),(cities[i][j+1])),((cities[i+1][j]),(cities[i+1][j+1]))
}
}
for ( i = 0; i< distances.length; i++) {
for (j = 0; j < distances[i].length; j++) {
distance = dist((distances[i][j]),(distances[i][j+1]),(distances[i+1][j]),(distances[i+1][j+1]))
}
}
}