for(...) { for(...) { for(...) { } } } I WILL write this and there's nothing you can do about it.

for(...) {
for(...) {
for(...) {
}
}
}

I WILL write this and there's nothing you can do about it.

Ape Out Shirt $21.68

Tip Your Landlord Shirt $21.68

Ape Out Shirt $21.68

  1. 2 years ago
    Anonymous

    That's cool.

  2. 2 years ago
    Anonymous

    >2 lines of unreachable code in just 6 lines total
    wont make it

    • 2 years ago
      Anonymous

      All 6 lines are unreachable because that doesn't compile
      retord

  3. 2 years ago
    Anonymous

    me printing an tensor

  4. 2 years ago
    Anonymous

    nakadashi

  5. 2 years ago
    Anonymous

    Does anyone have a better solution to iterate over a 3d array?

    • 2 years ago
      Anonymous

      bfs dfs

    • 2 years ago
      Anonymous

      for (int i = 0; i < width * depth * height; i++) {
      arr[i] = ...
      }

      • 2 years ago
        Anonymous

        >when your array goes above 1291 per side

        • 2 years ago
          Anonymous

          just use #define int unsigned long long
          and now you can get to almost 3 million per side

      • 2 years ago
        Anonymous

        Does this work? I know multidimensional arrays are all allocated together in memory, but I was wondering if you can index them like this or if the compiler will throw a fit.

        • 2 years ago
          Anonymous

          compiler complains

          • 2 years ago
            Anonymous

            I tested it and you can do it in C/C++ but you have to be clever and user pointer arithmetic.
            i=5
            j=6
            k=7
            int matrix[i][j][k];
            for(int n = 0; n < i*j*k; i++) {
            *(** matrix + n ) = .. ;
            }
            .. being what you want to do. Basically because its a pointer of pointer of pointer you dereference twice to get the base pointer use that to move to the value you want and then dereference the last pointer.

          • 2 years ago
            Anonymous

            just make one big array and then convert the index to coordinates

          • 2 years ago
            Anonymous

            This solution works better because it gives you the option to index via 3 points if you want it. Which might be what you want for other operations.

          • 2 years ago
            Anonymous

            it's also the simplest, fastest and smallest

          • 2 years ago
            Anonymous

            The array example isn't bigger its the same size just typed differently. Using the multidimensional array makes more indexing valid.

          • 2 years ago
            Anonymous

            Why would it be the fastest? Wouldn't the nested loops take the same time?

          • 2 years ago
            Anonymous

            It probably wouldn't, but that depends on the compiler. There might be more optimizations for a large array. The compiler might not realize that you are functionally doing the same thing with the pointer arithmetic example. A lot of modern compilers can do loop unrolling implicitly and allow for non dependent parallelization of loops. IE running multiple iterations of a loop at once using sperate cores.

      • 2 years ago
        Anonymous

        This is a better solution to get an integer overflow, for sure.

      • 2 years ago
        Anonymous

        >single for
        >instantly O(n)

    • 2 years ago
      Anonymous

      foreach (v in arr.SelectMany(x => x.SelectMany(x => x*~~
      {
      }

      • 2 years ago
        Anonymous

        works only for [][][], not for [,,]

        • 2 years ago
          Anonymous

          for [,,] just use Cast<T>()

      • 2 years ago
        Anonymous

        map3 = ((.).(.)) (>>= id) (=<<)

        disgusting...
        so this is the power of worktards?

      • 2 years ago
        Anonymous

        >allocating for each element
        why though

    • 2 years ago
      Anonymous

      map3 = ((.).(.)) (>>= id) (=<<)

      • 2 years ago
        Anonymous

        >(.).(.)

      • 2 years ago
        Anonymous

        >(.).(.)

        reported to hr for creating an unsafe work environment and also being ugly

      • 2 years ago
        Anonymous

        foreach (v in arr.SelectMany(x => x.SelectMany(x => x*~~
        {
        }

        for (int i = 0; i < width * depth * height; i++) {
        arr[i] = ...
        }

        bfs dfs

        How is any of this shit more readable than 3 nested for loops? You just made OP's code worse, congratulations

        • 2 years ago
          Anonymous

          True, at least everybody understand these needed for loops immediately. And got
          This style is quite universal in many languages (aka, they look very similar).

          for (int i = 0; i < width * depth * height; i++) {
          arr[i] = ...
          }

          This solution requires that nested loops can be flatten like this. But if you still need all the running variables x y z, then you're better off just using nested loops, unless you have compiler optimization or want to run it on gpu for example.

      • 2 years ago
        Anonymous

        >(.)(.)

        • 2 years ago
          Anonymous

          >(.).(.)

      • 2 years ago
        Anonymous

        booba

    • 2 years ago
      Anonymous

      for (…) for(…) for(…){

      }

    • 2 years ago
      Anonymous

      .&stuff() for |@arr

  6. 2 years ago
    Anonymous

    rape correction is needed for the O(n3) brat

  7. 2 years ago
    Anonymous

    coder:
    while(true)
    {

    }
    programmer:
    for(;;)
    {
    }

    • 2 years ago
      Anonymous

      chad:
      loop:
      goto loop;

      • 2 years ago
        Anonymous

        Ayy lmao

        • 2 years ago
          Anonymous

          Do you even know what 'ayy lmao' means, you underage redditor?

          • 2 years ago
            Anonymous

            ailens noise

    • 2 years ago
      Anonymous

      #define ever (;;)

      for ever
      {
      }

    • 2 years ago
      Anonymous

      where did the word code come from?

      • 2 years ago
        Anonymous

        From the Latin word "codex"

    • 2 years ago
      Anonymous

      🙁

      • 2 years ago
        Anonymous

        that's for being a homosexual and not writing in C

        • 2 years ago
          Anonymous

          I don't want nor need your stupid old confusing language sorry man

          • 2 years ago
            Anonymous

            C# I might use in my future Unity video game 🙂
            the other two though, I've heard nothing but bad things about, which is the label I also put obsessive snobby elitist cultists under.

            how is it confusing?
            if something doesnt work in c++ it usually just doesnt work, unless you want to spend an hour either rewriting it or do something confusing
            however, because of this there is almost always a good alternative in c++ which is even easier to use than the original
            this is proven just by the number of ways you can print something to the console or receive user input from it
            the only issue with this that i see is that it requires you to look up almost everything up, but thats what programming is, you take what others have learned and add it to your own program for further levels of abstraction, otherwise every programmer would have to go from printing hello world on the console to modern graphics on their own

          • 2 years ago
            Anonymous

            >if something doesnt work in c++ it usually just doesnt work
            That's the complete opposite of reality.
            In C++ development, 90% of the time is spent fighting against the language itself rather than implementing the business logic of your problem.

          • 2 years ago
            Anonymous

            have you ever considered that maybe you are just bad at programming?

          • 2 years ago
            Anonymous
      • 2 years ago
        Anonymous

        works in c,c++,c# haven't tried any other

        • 2 years ago
          Anonymous

          C# I might use in my future Unity video game 🙂
          the other two though, I've heard nothing but bad things about, which is the label I also put obsessive snobby elitist cultists under.

          • 2 years ago
            Anonymous

            >obsessive snobby elitist cultists
            that's the best part

      • 2 years ago
        Anonymous

        >``
        Typical front end """dev"""

        • 2 years ago
          Anonymous

          frick you "``" is best javascript feature

          • 2 years ago
            Anonymous

            Backticks:
            >allow injecting variables like ${this}
            >allow using quotations AND apostrophes without escapes

            Quote marks:
            >...

            Literally why would I ever not use backticks?
            Explain. Is there some tradeoff I'm unaware of?

            It's the same as prefixing every single string in C# with $ even though you're not doing interpolations most of the time
            It looks stupid and makes whoever is reading your code expect a reason for it to be present

        • 2 years ago
          Anonymous

          Backticks:
          >allow injecting variables like ${this}
          >allow using quotations AND apostrophes without escapes

          Quote marks:
          >...

          Literally why would I ever not use backticks?
          Explain. Is there some tradeoff I'm unaware of?

          • 2 years ago
            Anonymous

            >why would I ever not use backticks?
            Because it won't work on IE

          • 2 years ago
            Anonymous

            IEs EoL is in like 8 days

          • 2 years ago
            Anonymous

            Good, geriatrics and chinks frick off.

          • 2 years ago
            Anonymous

            ...Do I give a shit?

          • 2 years ago
            Anonymous

            Anyone using backticks is probably working with something like babeljs in their stack.

      • 2 years ago
        Anonymous

        Works in java.

        • 2 years ago
          Anonymous

          Demon

    • 2 years ago
      Anonymous

      #define ever ;;
      for (ever) {
      /* code here */
      }

    • 2 years ago
      Anonymous

      for me it's
      while(true)
      {
      }

  8. 2 years ago
    Anonymous

    As long as you break with goto.

  9. 2 years ago
    Anonymous

    I do nested for loops all the time. Could you create a function that returns after 2 levels and then you iterate over that with another for loop just so it looks cleaner?

  10. 2 years ago
    Anonymous
    • 2 years ago
      Anonymous

      DAMN CODE
      NEEDS LOOP CORRECTION

  11. 2 years ago
    Anonymous

    for(...) {for(...) {for(...) {}}}

    • 2 years ago
      Anonymous

      Based widescreen chad.

  12. 2 years ago
    Anonymous

    OP is right. stop reinventing the wheel

  13. 2 years ago
    Anonymous

    ToT

  14. 2 years ago
    Anonymous

    from itertools import product

    for i, j, k in product(I, J, K):
    ...

    Python chads strike again.

    • 2 years ago
      Anonymous

      what a waste of quads for a moron that can't read

      • 2 years ago
        Anonymous

        Sorry you got confused.

        what even is this shit? how do i break out of each loop? why is Python so moronic?

        >what even is this shit
        The same thing as 3 nested for loops, except elegant.
        >how do I break out of each loop
        I, J and K can be any sort of iterable, not just lists.

        • 2 years ago
          Anonymous

          >I, J and K can be any sort of iterable
          I don't see that in the type signature.

          • 2 years ago
            Anonymous

            itertools.product(*iterables,repeat=1)

            Although I realised they are consumed before running the loops so you couldn't break out based on what happens in the body of the loop.
            There's generally a better design pattern than breaking out of for loops though. That's kinda a hallmark of bad programmers.

          • 2 years ago
            Anonymous

            I wasn't the "break out of loop" guy. I was the (sarcastic) Python-type signature guy. And you didn't help me at all. In fact, you added an optional parameter I didn't even know existed.
            > Also, being able to break out of loops is not bad per se. I prefer explicit break options like "foldWhile/foldUntil" over "break/return".

    • 2 years ago
      Anonymous

      what even is this shit? how do i break out of each loop? why is Python so moronic?

    • 2 years ago
      Anonymous

      what does that even do?

      • 2 years ago
        Anonymous

        Whatever it does, it does it very inefficiently.

  15. 2 years ago
    Anonymous

    for(...) {
    break;
    for(...) {
    for(...) {
    }
    }
    }

  16. 2 years ago
    Anonymous

    do
    x <- ...
    y <- ...
    ...

  17. 2 years ago
    Anonymous

    O(n^3)

    • 2 years ago
      Anonymous

      Not him but if you have data that occupies cubic space then you're hard pressed to iterate it in any less than cubic time complexity

      • 2 years ago
        Anonymous

        Just invent a brand new algorithm, bro.

      • 2 years ago
        Anonymous

        I’m not saying anything about anything. Just doing the needful sir

  18. 2 years ago
    Anonymous

    k, if you had to iterate a matrix or object data structure that had a need for it so be it.

  19. 2 years ago
    Anonymous

    nakadashi

  20. 2 years ago
    Anonymous

    Python is pretty cool, I guess.

    #!/usr/bin/python3

    import numpy as np

    def main():
    array = np.random.randint(0, 10, size = (3,4,5))
    array.shape
    print(array)
    for elem in np.nditer(array):
    print(elem, end=' ')
    print()

    if __name__ == '__main__': main()

    • 2 years ago
      Anonymous

      isn't the point of python that you don't need a main function?

      • 2 years ago
        Anonymous

        Why would that be the point of python? The point of doing that is so the file can be used either as a script or as a module.

      • 2 years ago
        Anonymous

        All of that can be run without it, yes.

      • 2 years ago
        Anonymous

        no.

    • 2 years ago
      Anonymous

      >array.shape
      What does this do?

      • 2 years ago
        Anonymous

        shape the array into a nice cube

        • 2 years ago
          Anonymous

          It initializes as an ugly cube?

          • 2 years ago
            Anonymous

            don't be mean to the cube

          • 2 years ago
            Anonymous

            I'm trying but your pythonism is making it difficult. Why does it need reshaping? Why does the shape method look like a getter?

          • 2 years ago
            Anonymous

            >Why does it need reshaping?
            so it looks nice

          • 2 years ago
            Anonymous

            circular logic = circular logic
            uglyCube = cube `from` Python("apparently")

  21. 2 years ago
    Anonymous

    >not unrolling your loops
    ngmi

  22. 2 years ago
    Anonymous

    What's the problem?

  23. 2 years ago
    Anonymous

    There is absolutely nothing wrong with nested loops. If you need to iterate over all possible combinations of three indices, you need to iterate over all possible combinations of three indices, no amount of crying about imaginary "good code" practices will change that.

    Writing such an algorithm in literally any way is going to be worse. Nested loops are the most explicit and direct way to express this construct, there is no problem with nesting if your logic does in fact demand nested operations. Torvalds lied to you.

  24. 2 years ago
    Anonymous

    perl -e 'print for qq/op is a homosexualn/;'

  25. 2 years ago
    Anonymous

    What is actually wrong with nesting for loops?
    How else am I supposed to go through every element in a structure?

    • 2 years ago
      Anonymous

      You're supposed to use some design pattern or some shit.

      Apparently, actually saying what you want is now considered rude in programming as well.

    • 2 years ago
      Anonymous

      nothing
      you don't need to do anything else. this way is just as good as any other

  26. 2 years ago
    Anonymous

    There are cases, where this is totally normal?

    But if you imply to deliberately overengineer something, which can be programmed simpler, then.. well, do whatever you want. It can be fun to to do unnecessary stuff once in a while.

  27. 2 years ago
    Anonymous

    Yikes, why aren't you following best practices?

  28. 2 years ago
    Anonymous

    Okay. There are some possible uses cases for that pattern.

    • 2 years ago
      Anonymous

      Like what?

  29. 2 years ago
    Anonymous

    [...]

    i completely forgot that Wendy's used to roast people

  30. 2 years ago
    Anonymous

    I do this and I look like this.

    • 2 years ago
      Anonymous

      Cute

  31. 2 years ago
    Anonymous

    how else am i supposed to generate word lists if not with nested for loops?

    • 2 years ago
      Anonymous

      Parser combinators?

  32. 2 years ago
    Anonymous

    NooOoooOo!!! You should put the forloops in a function and then put that function inside a for loop and then make a function out of it!!

    def israelitelover69():
    for n in nog:...

    def frickjannies():
    for n in nig:
    israelitelover68()

    def frickyou():
    #this is O(n) because it only uses 1 for loop
    for c in cracka:
    frickjannies()

  33. 2 years ago
    Anonymous

    If you have a O(N**3) problem, you need a O(N**3) solution.

Your email address will not be published. Required fields are marked *