title: Is it better to access several times a value at array[i] or to stock this value in a variable (v=array[i]) and access this variable v instead?
body: <p>I'd like to know if it costs more to access several times a value at array[i] or  to stock the value as a new variable (v=array[i]) and access the variable v several times instead ?</p>
  
  <p>for example (in java), would it be better to write : </p>
  
  <pre><code>int [] array = {1,2,3,4,5};
  
  for(int i=0;i&lt;5;i++){
      if (array[i]&lt;0){
          System.out.println("negativ");
      }else if(array[i]&gt;0){
          System.out.println("positiv");
          if (array[i]==42){
              System.out.println("great answer");
          }
      }else{
          System.out.println("zero");
      }
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>int [] array = {1,2,3,4,5};
  int v;
  
  for(int i=0;i&lt;5;i++){
      v = array[i];
      if (v&lt;0){
          System.out.println("negativ");
      }else if(v&gt;0){
          System.out.println("positiv");
          if (v==42){
              System.out.println("great answer");
          }
      }else{
          System.out.println("zero");
      }
  }
  </code></pre>
  
  <p>Thank you for your help.</p>