Compulsive behavior is a core symptom of both obsessive compulsive disorder (OCD) and cocaine addiction (CA). Across both pathologies, one can identify a priori goal-directed actions (purportedly anxiolytic checking or washing in OCD and pleasure-seeking drug use in addiction) that turn into rigid, ritualized and repetitive behaviors over which the patient loose control. One possible psychopathological mechanism underlying compulsivity is behavioral inflexibility, namely a deficit in the aptitude to dynamically adapt to novel contexts and changing reward rules. The probabilistic reversal learning paradigm allows to objectively assess behavioral flexibility by challenging participants with a task where they have to learn through trials-and-errors which of two stimuli is the most-often rewarded one, while adjusting to sudden inconspicuous contingency reversals. We therefore hypothesized that both OCD and CA would be associated with impaired cognitive flexibility, as measured through perseverative response rate following contingency reversals in this task. Interestingly, impulsivity may also be assessed within this task via the tendency of participants to switch from one stimulus to the other following probabilistic errors. To investigate cognitive inflexibility in relation to CA and OCD respectively, we first compared the performance in a probabilistic reversal learning task of cocaine users, ex cocaine users (abstinent for 2 months or more), and controls, as well as that of participants from the general population whose obsessive-compulsive traits were assessed using the OCI-R, a well-validated self-questionnaire. Our task yielded results similar to those found in the literature: cocaine addicts changed their responses more often, and learned less effectively. Ex-cocaine addicts performed better than addicts but worse than controls, suggesting that addicts’ poor results may be in part explained by reversible cognitive consequences of addiction. Addicts with less cognitive impairments may also be less likely to relapse. Regarding the relationship of flexibility to subclinical OCD traits, we found no link between OCI-R score and perseveration, or between impulsiveness and excessive switching.