2016-12-04 2 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
  • повторить
Смежные вопросы