Reversing the process of a function

Asked

Viewed 27 times

0

I was thinking about a project for testing Skills, about a load bar and I thought, we can undo a modification on a page normally, but and do the opposite process ? for example, we have an automatic slideshow, every 1 second it changes image, always advancing, but when do we get to the end of the slideshow ? normally, it goes back the whole process at once, throwing us back to the first slide, but what if, at the end of the slideshow, we did the reverse process, going back every second, an image, and at the end of it, the process started again, how could this be done ?

EX:

need to perform a function over and over until it reaches the goal, when it reaches the goal, I need to call another function, which will perform the reverse of the previous one, which in turn, when finished, will call the first function again.

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 )
}
  • this will make the end, it takes turns between last and penultimate

  • No. Note that it changes direction only when it is less than 0 or more than the number of slides.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.