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<stack>
using namespace std;
#define N 1000002
vector<int> cl(N,-1);
class Queue{
	vector<int> v;
	int low;
	int high;
public:
	Queue():v(N,0),low(N-1),high(N-1){}
	void push(const int &t){
		v[low]=t;
		--low;
	}
	void pop(int &t){
		t=v[high];
		--high;
	}
	bool empty(){
		return high==low;
	}
};
int collatz(int n){
	int c=0;
	while(n<N){
		if(cl[n]!=-1)
			return c+cl[n];
		if(n%2==0){
			n/=2;
			++c;
		}else if(n%2==1){
			n=n*3+1;
			++c;
		}
	}
	return 0;
}
int main()
{
	/*Queue q;

	cl[1]=0;
	q.push(1);
	while( !q.empty() ){
		int t;
		q.pop(t);
		if( t*2<N ){
			if( cl[t*2]==0 ){
				cl[t*2]=cl[t]+1;
				q.push(t*2);
			}
		}
		if( (t-1)%3==0&&t>1 ){
			if( cl[(t-1)/3]==0 ){
				cl[(t-1)/3]=cl[t]+1;
				q.push((t-1)/3);
			}
		}
	}*/

	cl[1]=0;
	for(int i = 1; i < N; ++i){
		//if(i%5000==0)cout<<i<<endl;
		cl[i] = collatz(i);
	}

	while(true){
		int n;
		
		cin>>n;
		if(n==0)break;

		cout << cl[n] << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

int n;
while(1){
scanf("%d",&n);if(n==0)break;
int c=0;
while(n!=1){
if(n%2==0)n=n/2;
else {n=3*n+1;}
c++;
}

printf("%d\n",c);
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;
ll memo[1000005]={0};
ll func(ll n){
  if(n==1) return 0;
  if(memo[n]!=-1) return memo[n];
  if(n%2==0) return memo[n]=func(n/2)+1;
  else return memo[n]=func(n*3+1)+1;
}
int main(){
  for(int i=0;i<1000005;i++) memo[i]=-1;
  while(1){
    ll n;
    cin>>n;
    if(n==0) return 0;
    cout<<func(n)<<endl;
  }
}

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

typedef long long ll;
int n;

int main()
{
    while(cin >> n && n) {
        ll ans = 0;
        do {
            ans++;
            n = (n % 2) ? n * 3 + 1 : n / 2;
        } while(n != 1);
        cout << ans << endl;
    }
}

C++: #include <stdio.h>

int main(void)
{
	for(;;)
	{
		int a,n;
		scanf("%d",&a);
		if(a==0)
		{
			break;
		}
		for(n=0;;n++)
		{
			if(a==1)
			{
				break;
			}
			else if(a%2==1)
			{
				a=a*3+1;
			}
			else if(a%2==0)
			{
				a=a/2;
			}
		}
		printf("%d\n",n);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

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

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		int ans = 0;
		while (n != 1) {
			ans++;
			if (n % 2) {
				n = 3 * n + 1;
			}
			else {
				n /= 2;
			}
		}
		cout << ans << 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(1){
		cin>>n;
		if(n==0) break;
		int c=0;
		while(1){
			if(n==1) break;
			if(n%2) n=3*n+1;
			else n/=2;
			c++;
		}
		o(c);
	}
}

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

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

int main()
{
	int n;

	while(true){
		
		int count = 0;

		cin >> n;

		if(n==0)
			break;

		for(int i=0 ;n!=1 ;i++){

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

		cout << count << endl;

	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>
#include <stack>
#include <math.h>
#include <numeric>
#include <set>

using namespace std;
typedef long long Int;
#define REP(i , x) for(Int i = 0 ; i < x ; ++i)
typedef pair<int, int> P;


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

		while (n != 1){
			if (n & 1){
				n *= 3;
				++n;
			}
			else{
				n /= 2;
			}
			++ans;
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

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

map<int, int> memo;
int solve(int n)
{
	if(memo.count(n))
		return memo[n];
	if(n == 1)
		return 0;
	return memo[n] = 1 + (n%2==0 ? solve(n/2) : solve(n*3+1));
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		printf("%d\n", solve(n));
	}
	
	return 0;
}

C++: #include <iostream>

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

using namespace std;




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