Reversing the process of a function

0

I was thinking of a project to test skills, over a loading bar and I thought, we were able to undo a modification on a page normally, but did the opposite process? for example, we have an automatic slideshow, every 1 second he changes image, always moving forward, but when do we get to the end of the slideshow? usually, it returns the whole process in a single time, throwing us back to the first slide, but what if, at the end of the slideshow, we perform the reverse process, returning every second, an image, and at the end of it, the process, how could this be done?

EX:

I need to execute a function repeatedly until I reach the objective, when I reach the objective, I need to call another function, which will execute the inverse of the previous one, which in turn, when it finishes, will call the first function again.

    
asked by anonymous 20.03.2017 / 18:47

1 answer

1

Do something like this:

v_posicao_onde_estou : Integer
v_para_onde_estou_indo : Integer
v_quantide_de_slides : Integer;


function qual_slide : Integer
{
   if ( v_posicao_onde_estou < 0 ) 
        v_para_onde_estou_indo = 1
   else if ( v_posicao_onde_estou > v_quantidade_de_slides )  
       v_para_onde_estou_indo = -1

   v_posicao_onde_estou = v_posicao_onde_estou + v_para_onde_estou_indo;
   return v_posicao_onde_estou 

}

v_posicao_onde_estou = 0;
v_para_onde_estou_indo = 1;
v_quantide_de_slides = 100;


while ( true ) {
  mostra_slide ( qual_slide )
}
    
20.03.2017 / 18:58