Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

67
Views
Why the variable can't work in the loop of GEE?

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.

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs