Var not mutable?

The university I‘m studying at unfortunately also mandates Java for basically everything.
I feel like that’s also the main reason many people struggle with understanding the concept of pointers so much, if you actually understand how your computer works pointers are kind of obvious and Java sure doesn’t help with that!

2 Likes

The “why can’t I change a char in the middle with [z]” question is common enough that perhaps a reference to it should appear in the string literals section of the documentation, specifically mentioning the const-ness that requires “”.* – that (“”.* to convert to a byte-array) is in the documentation, scattered here and there, but it’s not in the string literals section. And, I never knew it worked on multi-line strings; don’t think that’s in the documentation.

1 Like

Multi-line string is just a slightly different way to write a string literal. Both are the same type. (Zero- terminated array of const bytes).

3 Likes

You can actually go a step further and the block can be labeled a too:

    const a = a: {
        var a = ...;
        // ...
        break :a a;
    };
6 Likes

That one is more intuitive, since it’s a block. I assume sequential block can be labeled the same as well. Tbh, where I needed a block I was always extracting it to a separate function. Now when I think about it, I might be wrong on that.