title: Why does a while loop and a for loop only return me the information of the last iteration?
body: <p>Here I am playing around with the coin gecko api. I am trying to log the price of bitcoin while 10 is not equal to 0, so basically 10 times. It works fine, only the iteration doesn't show accordingly. Instead it just shows the last iteration instead of every time it actually iterates.</p>
  <p>**seems as though iteration doesn't log accordingly inside the axios call but when I do console.log(iteration) just above it, It works fine.</p>
  <pre><code>    const [coinData, setCoinData] = useState([]) 
  
      iteration = 10
      while (iteration != 1) {
  
    
          axios.get(`https://api.coingecko.com/api/v3/coins/bitcoin/history?date=11-04-2022`).then((res) =&gt; {
  
                  console.log(iteration, res.data.market_data.current_price.usd)
                  setCoinData(iteration, res.data.market_data.current_price.usd)
          }).catch((err) =&gt; {
              console.log(err)
          })
        
          iteration--
      }
  </code></pre>
  <p>the console log returns this <code>9 : 1 42274.907370256085</code></p>
  <pre><code>instead of:
   9 42274.907370256085
   8 42274.907370256085
   7 42274.907370256085
  etc:
  </code></pre>