Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite for loop using continue

I'm writing a code that will run through each bin in a histogram and check if there are any non zero bins. If there are, it throws out an error message. My issue is, I want it to skip a bin because this bin should not be empty, but check all the other bins.

Only thing is this is creating an infinite loop. Here's my code

Int_t y;

for (int i = 0; i <= 100; i++) {
    y = hist - > GetBinContent(i)

    if (i = 1) continue;
    else if (y != 0) {
        std: cout << * * * * * ERROR * * * * * << std: endl;
        break;
    }

}

What's happening is it evaluates it for i = 0, skips i = 1, and then hits i = 2 and just continually evaluates that over and over again. If I take out the "if (i=1) continue;" line then it works.

Any ideas?

like image 381
CStarAlgebra Avatar asked Sep 17 '26 10:09

CStarAlgebra


1 Answers

Try this

if (i==1) continue;

i=1 mean you assign 1 to i. = means assign and == mean comparing .

In your code the value of i will always be 1 as you are using i=1

like image 72
Anik Islam Abhi Avatar answered Sep 18 '26 22:09

Anik Islam Abhi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!