Basic question here, just got curious about coding a simple formula out, and wanted to know if it’s possible to use a division operator for the increment in a c# for loop?
Using int X, would like to divide X repeatedly by some number Y until X <= some number Z.
for ( x = 0; x <= Z; X/Y) ? // Here, I throw an error at X/Y, also with (X/Y).
I think you mean
x = x / y.x/ydoes nothing useful on it’s own and, while it’s at least valid syntax in C and C++, I’m not sure C# will not allow it.But you should keep in mind that you have your condition “bass-ackward” (a) 🙂 This condition must be satisfied for the loop to continue, not to terminate.
So, if you mean (as you state) “… until X <= some number Z”, the loop should be:
In any case, since
xstarts at zero, and zero divided by anything (except zero) is still zero, the value ofxwill never change. I suspect you meant to startxat some larger value since you’re reducing it with the division operator and you want to terminate when it drops below a certain value.(a) To be honest, I’m not sure why this phrase is so popular. It’s a corruption of the obvious Spoonerism meaning things are the wrong way around but, as far as my limited knowledge of anatomy goes, I’m pretty certain the a** is supposed to be backwards 🙂