2

When I want to use "for" in GEE,I found out that the loop cannot be performed.The code is below:

var list=ee.List([1,2]);
var len = ee.Number(list.length());
for (var i =0;i<len;i++)
{
  var f = select(i);
  print(f);
}

I think the problem is the data format of "len". And I find a solution which I don't understand.The code is below:

list.evaluate(function(li){
for (var i=1; i<=li.length ; i++)
{
  var f = select(i);
  print(f);
}});

The API evaluation has been used in this condition, and the problem has been solved.
But I don't know why. And why I can't get the result with the first code.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
ilnaug
  • 19
  • 3

0 Answers0