for (i = 0; abs(i) < 6; i--)
for (i = 0; -i < 6; i--)
Changing the loop condition to i ^= 6; is another solution.
i ^= 6;
Ah-ha, a tricky one:
for (i = 0; i ^= 6; i--)
Ah, Sean beat me to it. :(
for (i = 0; i + 6; i--)
will stop when i + 6 = 0.
All solutions except the one in the first comment are correct. The first
one involves abs() function. The code would indeed end up
printing 6 dots but it doesn't meet the requirement in the question
since abs() is not an operator.
There is another very simple solution similar to the obvious solution I
have provided in the post. Instead of post-increment operator, use the
for (i = 0; i < 6; ++i)
The one involving the bitwise XOR operator is the one I had in my mind
while mentioning that one of the solutions is very interesting. I find
it interesting because it is not obvious at the first glance why it
works. Another curious property of this solution is that it works only
for an even number of dots. I'll write about this in another post.
Susam, absolute value is a mathematical operator. You didn't specify
the set of acceptable operators. :P
I am used to referring to |x| as the absolute value function. But yeah,
I see your point. The terminology is what we make it.
The problem statement could have specified that exactly one operator
from the C programming language must be added to or modified in the
given code snippet. That would have ruled out this little ambiguity.
Can someone explain how does the bitwise XOR work? Looks interesting.
Yes, I have posted a detailed explanation of the solution involving
bitwise XOR assignment operator here: Solutions to 'Loopy C puzzle'.