2016-12-04 25 views

回答

1

你还没有指定一种语言,所以这里是一些java。

算法仍然适用。

// the modifier to apply 
int modifier = 1; 

// min and max values 
int maxValue = 10; 
int minValue = -10; 

// the value of the count 
int count = 0; 

// loop forever 
while (true) { 

    // it higher then max or below min 
    if (count >= maxValue || count <= minValue) { 

     // invert the modifier 
     modifier = (modifier * -1); 
    } 

    // add modifier to count 
    count += modifier; 

    // use it 
    doSomethingWith(count); 
} 

这意志,

  • 开始在
  • 数到
  • 倒计时-10
  • 数到0
  • 重复