losertheone
losertheone

Reputation: 11

Java loop inside a loop

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?

Upvotes: 0

Views: 99

Answers (2)

Mik378
Mik378

Reputation: 22191

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.

Upvotes: 0

Blue Ice
Blue Ice

Reputation: 7930

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.

Upvotes: 2

Related Questions