In the range of the number of rows (i) = the number of columns (j), find the number of cycles of x[n,n]

In the range of number of rows (i) = number of columns (j), find the number of cycles of x[n,n].

var num = 0;
start:
for(var i = 0; i < 2; i++)
{
    for(var j = 0; j < 2; j++)
    {
        if(i = =1 && j == 1)
        {
            break start;
        }
    }
    num++;
}
alert(num);

Two-level loop: you can list a matrix:
because the condition in the for loop is i,j<2, so i has 0,1 j has 0,1 if the condition in if is i,j==1, so I'm looking for It is the number in row i+1 and column j+1
that is: find the number of times to find the number  in row 2 and column 2 in a matrix of 2 rows and 2 columns.

Start counting from the first row and first column, (0,0) num=1, (0,1) num=2 After 
the first row is calculated, then the second row (1,0) num=3, (1,1 ) num=4
So the number found in the second row and second column is found in the fourth loop. But num = 3, because num does not include the last loop.


Continue to give an example

var num = 0;
start:
for(var i = 0; i < 4; i++)
{
    for(var j = 0; j < 4; j++)
    {
        if(i = =2 && j == 2)
        {
            break start;
        }
    }
    num++;
}
alert(num);

num = 10 

From the above example, a formula can be drawn:
in the range of the number of rows (i) = the number of columns (j), find the number of cycles of x[n,n] num = n*i+n

Guess you like

Origin blog.csdn.net/michaelxuzhi___/article/details/109138593
Recommended