so if I have const int SIZE = 4; and a while loop

const int SIZE = 4;
int counter = 0;
    while(true) {
      // do something ...
      if(SIZE == counter+1) {cout << "Hello world"}
    }

why is this not working? and how is the right way to do it?

--- while(true) will run forever
--- You don't increment your counter IN the while loop
--- Place your condition not in an if-statement, but put it in the place of true
Success!

the value of SIzE is 4, the initial value of counter is 0. So SIZE never equals (counter+1). The value of counter never changes inside the loop.

how is the right way to do it?

Increment counter somewhere inside the loop but outside the if statement, most likely place is on line 4.

thanks for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.