I want to find event1 in my EEG data, followed by event2 and then extract reaction time between them for i=1:length(subjects)
    EEG = pop_loadset([sub_name{i},'.set'],folder);
    for k = 1:length(EEG.event)-1
        disp(k);
        if strcmp(EEG.event(k).type,con1)
            k = k+1;
            if strcmp(EEG.event(k+1).type,con2)
                rt = EEG.event(k+1).latency-EEG.event(k).latency;
            end
        end
    end
end
I'm guessing you are using Matlab. Your code is mainly sound, but a few comments:


don't use "i" or "j" as they are function names in Matlab.
don't change the value of a for loop variable inside the loop.


Here is you code, corrected:

for sub=1:length(subjects)
    EEG = pop_loadset([sub_name{sub},'.set'],folder);
    trial = 0;
    for eve = 1:length(EEG.event)
        if strcmp(EEG.event(trial).type,con1)
            trial = trial+1;
            trialonset(trial) = EEG.event(trial).latency;
        elseif strcmp(EEG.event(trial).type,con2)
            trialoffset(trial) = EEG.event(trial).latency; 
        end
    end
    rtlist{sub} = trialoffset-trialonset;
end