this post was submitted on 13 Dec 2025
648 points (97.6% liked)

Programmer Humor

28009 readers
1167 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] BassTurd@lemmy.world 5 points 1 week ago (1 children)

I know. OP asked what x was before the loop, and I just said it's an int. The int can be any value because as you pointed out it will be set to 0 in the first loop iteration.

[–] OshaqHennessey@midwest.social 2 points 1 week ago (1 children)

Shit, you're right. x is declared inside the loop, so it doesn't exist until the loop begins execution.

Technically, I suppose you could say the compiler will allocate memory for x without assigning a value before the loop is executed and... I'm understanding what you mean now, I think.

[–] anton@lemmy.blahaj.zone 1 points 1 week ago (2 children)

The code seems to be C-style language with curly braces and types in front for variable declarations, probably java. This means the variable must be declared of screen before the loop or it would not compile. It could have a previous value or be uninitialized, but that does not affect the end result.

[–] BassTurd@lemmy.world 1 points 1 week ago

I read in on C but it's also true for JavaScript. The code implies that x was declared as an int sometime previously, or if JavaScript, just an object if not assigned a value giving it a type.

[–] OshaqHennessey@midwest.social 1 points 1 week ago

Yeah, it does look like C now that I think about it. You're right about the end result too. I believe C# will let you do inline declaration and assignment like that, so maybe that's what we're looking at? Been a while, could be wrong