I was 41 when I left as commanding officer of a navy squadron. At the time I held the rank of a Commander (O-5). The only way to keep flying regularly after that is to be a Commander of a an Air Wing (or CAG...the guy that sends Maverick to TOP GUN in the first movie). That job is an O-6 (Navy CAPT) job.