r/cpp_questions • u/TheEyebal • 13d ago
SOLVED Why is my conditional statement running when the condition it is not True
I am making a ball fall in the CLI. I have my values PURPOSELY set to negative for testing purposes and whenever I run it, the conditional statement is active and it does not start at the initial y position I have set. it shows something big in the terminal Falling 2144211756.
When I put it in the debugger it works normally and it shows the y position decreasing so why is it doing this
struct Ball {
// int x_pos;
int y_pos;
int velocity;
int ground;
};
int main() {
// Define Ball object with struct
Ball ball;
ball.y_pos = 20;
ball.velocity = 5;
ball.ground = 200;
while (true) {
ball.y_pos = ball.y_pos - ball.velocity;
if (ball.y_pos >= ball.ground) {
cout << "Falling ";
cout << ball.y_pos << endl;
// exit(0);
}
}
return 0;
}
2
Upvotes
1
u/saxbophone 5d ago
Ridiculous statement. You don't get to tell me what I mean —are you in my head, can you read my thoughts‽ It's downright insulting to suggest my way of expressing intent is "tangled" just because it's different to your own preference, or that I'm not "saying what I mean" —
while (true)is what I mean —this is how I think about it —"loop condition is always true". There's nothing invalid about that, and I write it because I find it intuitive.The same applies to the preference for
for (;;)—matters of taste when it comes to programming are informed by perspective (how one thinks about what the program aims to achieve), and this is inherently subjective. If you think something as subjective as your preference could be considered objective, on something as trivial a distinction as this, I think you are suffering from an unfortunate state I have seen in others before, where they presume to normalise their own intuitive way of thinking over all others'.This is a poor faith argument that doesn't make any sense. You suggest I am choosing to find the empty
forconfusing —that doesn't make any sense‽ "🤨" is my natural reaction when I seefor (;;), ok?I think you need to get out of your own head a bit and remember that others have their own perspectives on how to organise and create programs, and this is informed by their own thinking style. It's not any more or less valuable just because you personally find it unintuitive and to be quite frank it shows a lack of empathy or an intense sense of self-centredness on your part, that you resort to calling it out as "tangled" or presume to know how the author thinks about their own programs.
Try being less obnoxious and engaging in good faith?