HienPham
HienPham

Reputation: 1030

Misunderstanding the loop in C++?

I have some problem with C++ loop cycle,here is my code :

    for (int ii = 1; ii <= 4; ii++)
    {
        if (ii==1)
        {
            ro = 4;
            ratio = 0.85;
        }
        if (ii == 2)
        {
            ro = 6;
            ratio = 0.8;
        }
        if (ii == 3)
        {
            ro = 8;
            ratio = 0.9;
        }
        if (ii == 4)
        {
            ro = 10;
            ratio = 0.5;
        }

       function(ro,ratio);

       if (ii = 1)
       {
          cir4 = cir.clone();
          k4 = k3.clone();
       }
       if (ii = 2)
       {
          cir6 = cir.clone();
          k6 = k3.clone();
       }
       if (ii=3)
       {
          cir8 = cir.clone();
          k8 = k3.clone();
       }
       if (ii = 4)
       {
          cir10 = cir.clone();
          k10 = k3.clone();
       }
  }

my function(ro,ratio) works fine which each pair of ro-ratio outside of the loop for and it returns different result of Mat cir=function(ro , ratio) which each pair (in this case cir4 # cir6 # cir8 # cir10 );but when i put it inside the loop it always returns the same result : cir4 = cir6 = cir8 = cir10 = function(ro = 4 , ratio = 0.85)

I have no idea why. Am i misunderstanding how the loop for works in C++ ?

Upvotes: 0

Views: 79

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254461

Use == not = for comparison.

You've got it right in the first block of if statements, but not the second.

Upvotes: 12

Related Questions