▲ 651 ▼ More code = more better (lemmy.zip) submitted 7 months ago by cm0002@lemmy.zip to c/programmer_humor@programming.dev 92 comments fedilink hide all child comments
[–] BassTurd@lemmy.world 15 points 7 months ago (1 child) An int. Value doesn't matter because it's overwritten. permalink fedilink source parent hideshow 2 child comments replies: [–] OshaqHennessey@midwest.social 3 points 7 months ago (1 child) Not in this case. First, i is declared and assigned a value of 0. Next, x is declared and assigned a value of -i or -0. On the first loop iteration, i will decrement to -1, perform the conditional check, then execute the loop body which will assign x to -i or -(-1) or positive 1, and so on. The only time a variable is created without a value is if you declare one without assigning a value like with [int]i; permalink fedilink source parent hideshow 2 child comments replies: [–] BassTurd@lemmy.world 5 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] OshaqHennessey@midwest.social 2 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] anton@lemmy.blahaj.zone 1 point 7 months 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. permalink fedilink source parent hideshow 4 child comments replies: [–] OshaqHennessey@midwest.social 1 point 7 months 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 permalink fedilink source parent [–] BassTurd@lemmy.world 1 point 7 months 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. permalink fedilink source parent
[–] OshaqHennessey@midwest.social 3 points 7 months ago (1 child) Not in this case. First, i is declared and assigned a value of 0. Next, x is declared and assigned a value of -i or -0. On the first loop iteration, i will decrement to -1, perform the conditional check, then execute the loop body which will assign x to -i or -(-1) or positive 1, and so on. The only time a variable is created without a value is if you declare one without assigning a value like with [int]i; permalink fedilink source parent hideshow 2 child comments replies: [–] BassTurd@lemmy.world 5 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] OshaqHennessey@midwest.social 2 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] anton@lemmy.blahaj.zone 1 point 7 months 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. permalink fedilink source parent hideshow 4 child comments replies: [–] OshaqHennessey@midwest.social 1 point 7 months 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 permalink fedilink source parent [–] BassTurd@lemmy.world 1 point 7 months 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. permalink fedilink source parent
[–] BassTurd@lemmy.world 5 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] OshaqHennessey@midwest.social 2 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] anton@lemmy.blahaj.zone 1 point 7 months 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. permalink fedilink source parent hideshow 4 child comments replies: [–] OshaqHennessey@midwest.social 1 point 7 months 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 permalink fedilink source parent [–] BassTurd@lemmy.world 1 point 7 months 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. permalink fedilink source parent
[–] OshaqHennessey@midwest.social 2 points 7 months ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] anton@lemmy.blahaj.zone 1 point 7 months 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. permalink fedilink source parent hideshow 4 child comments replies: [–] OshaqHennessey@midwest.social 1 point 7 months 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 permalink fedilink source parent [–] BassTurd@lemmy.world 1 point 7 months 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. permalink fedilink source parent
[–] anton@lemmy.blahaj.zone 1 point 7 months 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. permalink fedilink source parent hideshow 4 child comments replies: [–] OshaqHennessey@midwest.social 1 point 7 months 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 permalink fedilink source parent [–] BassTurd@lemmy.world 1 point 7 months 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. permalink fedilink source parent
[–] OshaqHennessey@midwest.social 1 point 7 months 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 permalink fedilink source parent
[–] BassTurd@lemmy.world 1 point 7 months 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. permalink fedilink source parent