Sample and hold

i have no code but i have tried to make one, but as a said i am new to this programming langue so i wonder i some of you can come upp with a code.