Circle of fifths
Each time we went to a sharper key we took the note which was the 5th note of the previous scale (G, with one sharp, was the 5th note of C major.  D, with two sharps, was the 5th note of G, etc.).