# If Statement in function does not evaluate

I've written a function that should try to simulate a "triangle-wave-signal", given a few parameters. It looks like this:

tria[p_, s_, t_, ts_] := (
Module[{pps = s/(2 p), z = 0, cs = 0, cpos = 0, spp = 2/(s/(2 p)),
ct = 0, ret = {}},
For[i = 0, i < 2 p, i++,
For[j = 0, j < pps, j++,
AppendTo[ret, {ct, cs}];
ct = ct + ts;
cpos += 1;
spp *= If[TrueQ[cpos == s/(2 p)], cpos = 0; -1, 1, 1];
cs += spp;
];
]; ret
]
)


Most of it is unimportant, but here is the line that doesn't work:

spp *= If[TrueQ[cpos == s/(2 p)], cpos = 0; -1, 1, 1];


I don't know if I'm right, but I have a feeling that the If-Statement simply doesn't do anything. I can also write it in a way that the multiplication happens inside the statement, but still, nothing changes. Weirdly, if I execute this If-Statement alone (Outside of the function), it works... What am I missing here? Why isn't it working like it should?

• Remove the TrueQ part. The expression cpos == s/(2 p) will evaluate to True or False when numbers are plugged in already. – march Jan 21 '16 at 18:18
• By the way, you can check to see if that expression is doing anything by wrapping the expression cpos == s/(2 p) ins Sow Sow[cpos == s/(2 p)] and when you run the function using Reap: Reap@tria[1, 4, 2, 1] will return a list: the first element is the output of the function and the second element is a list of the instances of the Sowed expression. In this case, it clearly is doing something. Reap-Sow is nice for debugging, among many other things. By the way, what makes you think it's not doing anything? – march Jan 21 '16 at 18:24
• @march Weird, last time I tried removing the TrueQ it didn't work... Now it does. Thanks a lot! Now I just have to fix it so it ranges from -1 to 1 instead of 0 to 2, but that should be easy enough. – AnotherStudent Jan 21 '16 at 18:36
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jan 21 '16 at 19:01

a = 3;