• Moredekai@lemmy.world
      link
      fedilink
      arrow-up
      40
      ·
      24 hours ago

      It’s a standard formatted for-loop. It’s creating the integer variable i, and setting it to zero. The second part is saying “do this while i is less than 10”, and the last part is saying what to do after the loop runs once -‐ increment i by 1. Under this would be the actual stuff you want to be doing in that loop. Assuming nothing in the rest of the code is manipulating i, it’ll do this 10 times and then move on

      • Fermion@feddit.nl
        link
        fedilink
        arrow-up
        6
        ·
        22 hours ago

        I would also add that usually i will be used inside the code block to index locations within whatever data structures need to be accessed. Keeping track of how many times the loop has run has more utility than just making sure something is repeated 10 times.

    • jqubed@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      23 hours ago

      @Moredekai@lemmy.world posted a detailed explanation of what it’s doing, but just to chime in that it’s an extremely basic part of programming. Probably a first week of class if not first day of class thing that would be taught. I haven’t done anything that could be considered programming since 2002 and took my first class as an elective in high school in 2000 but still recognize it.

    • JustAnotherKay@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      23 hours ago

      for( int i = 0; i < 10; i ++)

      This reads as “assign an integer to the variable I and put a 0 in that spot. Do the following code, and once completed add 1 to I. Repeat until I reaches 10.”

      Int I = 0 initiates I, tells the compiler it’s an integer (whole number) and assigns 0 to it all at once.

      I ++ can be written a few ways, but they all say “add 1 to I”

      I < 10 tells it to stop at 10

      For tells it to loop, and starts a block which is what will actually be looping

      Edits: A couple of clarifications