We are about to switch to a new forum software. Until then we have removed the registration on this forum.
For fun, I am trying to take a integer and display it in boxes ala a speedometer: each digit in a frame. I am using a For statement to extract each digit. The results are that it appears to go thru the loop the correct number of times but only the results of the first pass thru the loop are printed. The code is:
int n = 567; int p,j; int xyz = 6; println ("starting with:" + n + " for " + xyz + " digits"); for (p =0; p < xyz; p = p + 1); { j = n -((n/10)*10); n = n/10; println (p +"=----------->"+j+"<------ n = " + n); }
Answers
You have a spare ; immediately after the for ()
end of line 5.
meaningful variable names are good, calling things p, n and j isn't.
also, n - ((n / 10) * 10) is n % 10
https://processing.org/reference/modulo.html
I see the extra ; but do not understand why that would cause the problem.
Thanks for the modulo input. I will use it.
It ends the statement you end up with 2 separated statments
1-
2-
more explanation
basically the for-loop command defines its properties inside
()
and expects a command right after the (...) part.This command closes with a
;
like a normal line.Now when you put a
;
after the(...)
part, we say: execute all between(...)
and;
which is unfortunately nothing.