Storage Conditional writes sample

We want use Conditional writes to update some shared data. we try write use condition write, if write fail with reject by version, we will read newest data from storage,and calcute new data base last read data ,and try write again, until success. can give a sample code to do this