# Avoid trouble while using two if Statements?

Posted 10 months ago
479 Views
|
3 Replies
|
1 Total Likes
|
 Hi ! How are you guys! So I am using the following code to randomly to choose x or y first, then another if statement to choose to add or minus. However, some error pop out and I don't know how to solve. It would be so appreciated if you guys can help with this silly problem! Thanks so much!!! Code: x = 0; y = 0; lstx = {}; lsty = {}; For[i = 0, i < 1000, i++, a = RandomReal[]; b = RandomReal[]; c = RandomReal[]; If[ c < 0.5, (If[a > 0.5, x = x + 1, x = x - 1]; AppendTo[lstx, x]), (If[b > 0.5, y = y + 1, y = y - 1]; AppendTo[lsty, y]) ]] error:\$RecursionLimit Attachments:
3 Replies
Sort By:
Posted 10 months ago
 My code( Sorry for the previous inconvenience): x = 0; y = 0; lstx = {}; lsty = {}; For[i = 0, i < 1000, i++, a = RandomReal[]; b = RandomReal[]; c = RandomReal[]; If[ c < 0.5, (If[a > 0.5, x = x + 1, x = x - 1]; AppendTo[lstx, x]), (If[b > 0.5, y = y + 1, y = y - 1]; AppendTo[lsty, y]) ]]