Code question.

Hey there all,

I'm trying to understand how this for loop works but I'm a little confused.
To give you context this section is preceded by a for loop that turns all internal pullups on.
So obviously, when digital read goes low it triggers a prerequisite in this loop and changes
an array element.
I will comment in the code to show my own thought process.
If I'm wrong please correct me.

for(int i=0;i<15;i++)    //here we loop through the first 15 inputs waiting for a button press
  {
  if(digitalRead(i)==0)   //one of the buttons goes low and triggers this prerequisite
      {
      if(stis[i]==0)          //all of the stis elements are set at 0 already so this if statement is true.
        {
          if(i<10)              
          broj=broj+i;

          if(i==10)
          broj=broj+"+";

           if(i==11)
          broj=broj+"-";

           if(i==12)
          broj=broj+"*";

           if(i==13)
          broj=broj+"/";

           if(i==14)
          broj=broj+".";

          
          
          
          stis[i]=1;        //so here the element is changed to 1 so then how would it trigger any of the  
        }                      //if statements above if the next line changes that stis element back to 0
      }else{stis[i]=0;} //with this line?
  }

Would I be correct to say that what happens is the code loops through here once
reads that reads that a button is pressed, changes the stis element to 1, goes back to the
top of the code, checks for a button press again, finds that the element in stis is there and then changes the broj string, then changes the stis element back 0?

  if(digitalRead(i)==0)   //one of the buttons goes low and triggers this prerequisite

One of the PINS IS low... You don't read switches, or even worse buttons. You read pins. There is nothing in that line of code that looks for a transition (goes). It simply compares the current state (is).

      if(stis[i]==0)          //all of the stis elements are set at 0 already so this if statement is true.

Perhaps on the first iteration of that loop that is true. Obviously, on subsequent iterations, that might not be true.

          stis[i]=1;        //so here the element is changed to 1 so then how would it trigger any of the

Instead of using names that make sense, to English speakers, like currentState and previousState, the authow of that code used stis to mean previous state. Perhaps in his/her native language, stis means something like previous state.

What is happening is that that code uses stis to keep track of the current state of the pin, so that a change, from released to pressed, can be detected.

Thank you for clarifying PaulS.
This will be very helpful.