0

What I want to do here is a loop inside a loop and I want to increment the inner loop by the value of the counter in the outer loop.

The error I get is "Not a statement", pointing at "b + s ) inside the inner for-loop

for( int s =1; s < 100; s++){
    if( 100 % s == 0){
        for( int b = 0; b < 100; b + s ){
            locker[b] = locker[b] * (-1);
        }
    }
}

Is my goal achievable at all?

9
  • What is b + s meant to do? Commented Apr 7, 2014 at 22:06
  • 4
    Try b += s instead of b + s Commented Apr 7, 2014 at 22:06
  • 2
    Do you mean b += s? Commented Apr 7, 2014 at 22:06
  • b is the counter for the inner loop and the value is supposed to increment by s from the outer-loop Commented Apr 7, 2014 at 22:07
  • 1
    Also, to save a small operation, you can change locker[b] = locker[b] * (-1); to locker[b] = -locker[b]; Commented Apr 7, 2014 at 22:11

2 Answers 2

2

Try changing this line:

for( int b = 0; b < 100; b + s ){

Into:

for( int b = 0; b < 100; b += s ){

This operator, also known as the addition assignment operator, will add s to b's original value and store it back into b.

Information is from Azure's comment.

Sign up to request clarification or add additional context in comments.

Comments

0

Where is b + s result stored?

What would be the point to let the third part's result of for loop, "volatilized"? Maybe for side effects only..but would be too hidden.. not recommended.

Without a storing variable (pleonasm :)), your loop would end up with the same outcome at each step.

Thus, b += s would make more sense since b would store each new value, then usable in your loop content.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.