在伪代码中遍历M × N矩阵


Iteration across M x N matrix in pseudocode?

由于一些bug,我不能发布代码,所以我要给你们写伪代码。请用代码和数学来回答。我的数学很糟糕,而试图通过代码来计算数学对我来说是不可能完成的任务。

我的伪代码只使用数字和字母,这将形成一个2x2矩阵,但我希望能够以这种方式迭代m × n矩阵。我只是觉得从特定的(没有变量)到一般的(包含变量)更容易。

Letter a, letter b; number 1, number 2 ==>
Letter a id=1, letter b id=1 | 
number 1 id=1, number 2 id=2 |
Letter_by_Number 1by1, Letter_by_Number 1by2, Letter_by_Number 2by1, Letter_by_Number 2by2

谁能告诉我如何在c++, Python, PHP的SimpleXML或XSL中做到这一点?如果我能掌握这些语言中的任何一种,我想我就能解决其他问题。

像这样?

$m = 2; 
$n = 2; 
for($i = 1; $i <= $m; $i++) {
    for($j = 1; $j <= $n; $j++) {
         echo $i." x ".$j."'n"; 
    }
}

结果:

1 x 1
1 x 2
2 x 1
2 x 2

您只想遍历一个二维数组。在伪代码中,你可以这样做:

for ( i = 0; i < M; i++ ) {
  for ( j = 0; j < N; j++ ) {
    do stuff with array element i,j
  }
}