Loop inside loop - find latest loop value

please format code with </> button * homework policy * asking questions

Hi there, I still have some issues with nested loops conceptually.
Is there a way to know what would be the last value of ‘angle’ before the loop repeats itself? Is it 359? Asking this as the output I get is a rotating figure BUT at a certain point in time it doesn’t rotate anymore, so trying to obtain that final static output without the double loop if possible.
PS: If I remove the 2nd loop and substitute ‘angle’ by 359 I don’t obtain the same result. Thanks.

float angle = 0;
for(int i = 1; i < 200; i++) {
   rotate(radians(angle));
     for(int j = 1; j < 360; j++) {
       angle += 1;
     }

Hello @Erif ,

Put some print() or println() statements in there to see the values:

float angle = 0;
for (int i = 1; i < 5; i++) 
  {
  //println(i, angle);  
  for (int j = 1; j < 5; j++) 
    {
    angle += 1;
    println(i, j, angle);
    } 
  }

:)

Ah yeah cool!! I had put println(i) but didn’t occur to me to add j and angle haha. Thanks!

1 Like