Java Example What Does Tis Do?


Recommended Posts

while (X<0)

x += sTwoPI;

)

I have never seen += or the opisite -=

thanks

Link to post
Share on other sites

it appears to be a counter. it will keep looping until the value of x is less then 0

I think these are equivailant(forgot my syntax, I don't know any java)

x += sTwoPI

x = x + sTwoPI

I will use python for an example. Lets say you want somthing to loop 5 times, each time it will print the value of "x". Once the value of x hits 5 it will stop

x = 0
while x < 5:
x = x + 1
print x

this is the same thing using the other syntax

x = 0
while x < 5:
x += 1
print x

My programming skills are so forgotten, I had to look up the syntax to do this.

Edited by shanenin
Link to post
Share on other sites

so your saying its the same as doing a x++?

Link to post
Share on other sites

shanenin is correct. Those are compound assignment operators. x op= y is equivalent to x = x op y (except that x is evaluated once instead twice).

Edited by jcl
Link to post
Share on other sites
to be honest, I have never seen that syntax. Is that java?

c++ java, c# and VB and C

X++ would incrament X by one , its the same as X = X + 1

X-- is the opisite

Link to post
Share on other sites

so since my entier class is as such

public static double fixAzimuth_02PI (double x)

while (x < 0)

{

x += sTwoPI;

}

while (x > sTwoPI)

{

x -= sTwoPi;

}

return x;

}

private static final double sTwoPi = 2.0 * Math.PI;

so I gather this is keeping x between 0 and 2*PI

Link to post
Share on other sites
X++ would incrament X by one , its the same as X = X + 1

Not quite the same. x = x + 1 increments x and returns the new value, whereas x++ increments x and returns the previous value.

so I gather this is keeping x between 0 and 2*PI

Looks like but I'm not sure it's correct. Seem like the angle θ should be normalized to 0 <= θ < 2π rather than 0 < θ <= 2π.

Edited by jcl
Link to post
Share on other sites

you are correct, ++x would incrament and send incramented while X++ incarments and sends prior but x is still incramented. so its the same as ++x

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...