Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		k := 0
		for n > 1 {
			if n&1 != 0 {
				n = n+((n+1)>>1)
				k+=2
			} else {
				n >>= 1
				k++
			}
		}
		fmt.Println(k)
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

const int INF = 1 << 30;

int main()
{
  const int MAX = 1000000+1;
  vector<int> dp(MAX, INF);
  dp[1] = 0;
  queue<int> que;
  que.push(1);
  while (!que.empty()) {
    int num = que.front();
    que.pop();

    int even = num * 2;
    if (even < MAX && dp[even] > dp[num]+1) {
      dp[even] = dp[num]+1;
      que.push(even);
    }

    int odd = (num-1) / 3;
    if (odd > 0 && odd < MAX && dp[odd] > dp[num]+1) {
      dp[odd] = dp[num]+1;
      que.push(odd);
    }
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    cout << dp[n] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, t, c;
	while (cin >> n && n)
	{
		c = 0;
		t = n;
		while (t != 1)
		{
			if (!(t%2))	t /= 2;
			else		t = t * 3 + 1;
			c++;
		}
		cout << c << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int i=0;
    while(n!=1){
      i++;
      if(n%2)n=3*n+1;
      else   n/=2;
    }
    cout<<i<<endl;
  }
}

C++: #include<iostream>
using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		int ans = 0;
		while(n != 1){
			if(n % 2 == 0) n /= 2;
			else n = n * 3 + 1;
			ans++;
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int t,bell;
  while(1){
    t=0;
    cin >> bell;
    if(bell==0){
      break;
    }
    while(bell!=1){
      t++;
      if(bell%2==0){
	bell/=2;
      }
      else{
	bell*=3;
	bell++;
      }
    }
    cout << t << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int memo[1111111];
int dfs(int v){
  if(~memo[v]) return memo[v];
  if(v==1) return 0;
  if(v%2) return dfs(v*3+1)+1;
  else return dfs(v/2)+1;
}
signed main(){
  memset(memo,-1,sizeof(memo));
  int n;
  while(cin>>n,n) cout<<dfs(n)<<endl;
  return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
	int n;
	while(1){
		int count=0;
		cin>>n;
		if(n==0)break;
		while(n!=1){
			if(n%2==0){
				n/=2;
				count++;
			}else{
				n=n*3+1;
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n){
		int c=0;
		while(1){
			if(n==1) break;
			if(n%2) n=3*n+1;
			else n/=2;
			c++;
		}
		o(c);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000001;
int dp[MAXN];

int rec(int n) {
  int &res = dp[n];
  if(res != -1) return res;
  if(n == 1) return res = 0;
  return res = rec(n%2 == 0 ? n/2 : n*3 + 1) + 1;
}

int main() {
  int n;
  fill(dp, dp+MAXN, -1);
  while(cin >> n && n) {
    cout << rec(n) << endl;
  }
  return 0;
}

C++: while num = gets.to_i
	count = 0
	if num == 0
		break
	end
	while num != 1
	if (num % 2) == 0
			num = num / 2
			count = count + 1
		else 
			num = (num * 3) + 1
			count = count + 1
		end
	end
	puts count
end

C++: #include <iostream>
#include <algorithm>
using namespace std;

int main(void){
	int n, ct = 0;
	cin >> n;
	while (n != 1){
		if (n % 2 == 0){
			n = n / 2;
		}
		else {
			n = n * 3 + 1;
		}
		ct++;
	}
	cout << ct << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  while( cin >> n, n ) {
    int cnt = 0;

    while( n != 1 ) {
      if( n % 2 == 0 ) n /= 2;
      else n = n * 3 + 1;
      cnt++;
    }

    cout << cnt << endl;

  }

}

C++: #include <iostream>

using namespace std;

int main(){
	int n,i;
	while(cin>>n,n){
		i=0;
		while(n!=1){
			if(n%2==0)n/=2;
			else if(n%2==1)n=(n*3)+1;
			i++;
		}
		cout<<i<<endl;
	}
}

C++: #include <iostream>
using namespace std;

int main(){
	int a, count;
	while(1){
		count = 0;
		cin >> a;
		if(a == 0)
			break;
		while(a != 1){
			if(a%2 == 0){
				a /= 2;
			}else{
				a = a*3+1;
			}
			count++;
		}
		cout << count << endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;


int main(){
    long long int n, ans = 0;
    while (1){
	cin >> n;
	if (n == 0) break;
	ans = 0;
	while (n != 1){
	    if (n % 2 == 0) n /= 2;
	    else n = 3 * n + 1;
	    ans++;
	}
	cout << ans << endl;
    }
}

C++: #include<iostream>
using namespace std;

int collatz(int);
int count(int);

int main(void){
  int num;

  while(1){

    cin >> num;
    if( num == 0 ) break;

    cout << collatz(num) << endl;

  }

  return 0;
}

int collatz(int num){
  int cnt = 0;
  
  while( num != 1 ){
    
    switch(num%2){
      
    case 0:
      num /= 2;
      break;
      
    case 1:
      num = num*3 + 1;
      break;      
    }
    cnt++;
  }  
  return cnt;
}

C++: #include<stdio.h>
main(){int n;while(scanf("%d",&n),n){int c=0;while(n-1){if(n%2)n=3*n+1;else n/=2;c++;}printf("%d\n",c);}}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;



int main(){
	ll n,ans=0;
	while(cin>>n){
		if(n==0)break;
		ans=0;
		while(1){
			if(n%2==0)n/=2;
			else n=n*3+1;
			ans++;
			if(n==1)break;
		}
		cout<<ans<<endl;
	}
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){

  int n;

  while(cin>>n,n){

	int cnt=0;

	while(1){
	  if(n==1)
		break;
	  else if(n%2==0){
		cnt++;
		n=n/2;
	  }
	  else if(n%2==1){
		cnt++;
		n=n*3+1;
	  }
	  
	}

	cout<<cnt<<endl;
	
  }

}

C++: #include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    int cnt = 0;

    while( n != 1 ){
      
      if( n % 2 == 0 ) n /= 2;
      else n = 3*n + 1;
      cnt++;

      }
    cout << cnt << endl;
  }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(cin>>n,n){
    int cnt=0;
    while(n!=1){
      if(n%2){
	n*=3;
	n+=1;
      }else{
	n/=2;
      }
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
    int n;
    while (cin >> n) {
        int count = 0;
        while (n > 1) {
            if (n % 2 == 0) {
                n /= 2;
            } else {
                n = 3 * n + 1;
            }
            count++;
        }
        cout << count << endl;
    }
}