\(\(\( (*\ 
      This\ is\ the\ 3  x + 
        1\ map . \ It\ takes\ as\ input\ an\ odd\ number, \ 
      and\ outputs\ \((3  x + 1)\)/2^k, \ 
      where\ k\ is\ the\ largest\ power\ of\ 2\ dividing\ 3  x + 
        1. \ The\ second\ input, \ n, \ 
      controls\ the\ printing . \ if\ n = 
        0\ then\ it\ just\ prints\ \((3  x + 1)\)/2^k; \ 
      if\ n\  ≥ \ 
        1\ it\ prints\ n\ as\ well . \ 
            this\ is\ useful\ when\ you\ want\ to\ print\ several\ iterates\ of\ a\ starting\ seed, \ 
      and\ keep\ track\ of\ which\ iterate\ has\ which\ \(\(value\)\(.\)\)*) \)\(
\)\(\(M[x_, n_]\  := \ 
        Module[{}, 
y\  = \ 
            3\ x\  + \ 1; 
m\  = \ 
            n; 
While[\ Mod[y, 2]\  == \ 0, \ 
            y\  = \ y/2]; 
If[n == 0, \ Print[y], 
            Print["Term ", \ m, " is ", 
              y]]; 
m\  = \ 
            m + 1;
];\)

 (*\ 
      This\ function\ uses\ the\ function\ M[]\ from\ above\ to\ print\ the\ iterates\ of\ a\ starting\ seed\ until\ 1\ is\ reached\ *) 

    \(IM[x_]\  := \ 
        Module[{}, 
y\  = \ 
            x; 
Print["Term 0 is ", \ 
            y]; 
n\  = \ 1; \ 
m\  = \ 
            n; 
While[\ y\  > \ 1, \ 
            M[y, m]];
];\)\)\)\)

M[7, 0]

IM[
      7]

IM[27]