Go: package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		an := make([]int, n)
		min := 1000000
		for i := 0; i < n; i++ {
			an[i] = nextInt()
		}
		sort.Ints(an)
		for i := 1; i < n; i++ {
			sub := an[i] - an[i-1]
			if min > sub {
				min = sub
			}
		}
		fmt.Println(min)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

C++: #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		ll n;
		cin>>n;
		if(n==0) break;
		vector<ll> a(n);
		REP(i, n) cin>>a[i];
		ll gap = INF;
		sort(ALL(a));
		FOR(i, 1, n) gap = min(gap, a[i] - a[i - 1]);
		cout<<gap<<endl;
	}
}

C++: #include <iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define INF 9999999

int main() {

	int n, an;
	vector<int> vec;
	int ans = INF;

	while (1) {

		cin >> n;
		if (n == 0) break;
		//??\???
		for (int i = 0; i < n; i++) {
			cin >> an;
			vec.push_back(an);
		}
		//?????????
		sort(vec.begin(), vec.end());
		//??????????°?????¨????
		for (int i = 0; i < n - 1; i++) {
			if (vec[i + 1] - vec[i] < ans) {
				ans = vec[i + 1] - vec[i];
			}
		}
		//??????
		cout << ans << endl;
		//?????????
		vec.clear();
		ans = INF;
	}
	return 0;
}

C++: 
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

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

		vector<int> a(n);

		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		int ans = INF;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ans = min(ans,abs(a[i] - a[j]));
			}
		}

		cout << ans << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {

	int n;
	while(cin >> n, n){
		vector<int> a(n);
		rep(i, n) cin >> a[i];
		
		int ans = IINF;
		rep(i, n){
			REP(j, i+1, n){
				ans = min(ans, abs(a[i] - a[j]));
			}
		}
		
		cout << ans << endl;
		
	}

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }

        int mindif = 10000000;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                mindif = min(mindif, abs(a[i] - a[j]));
            }
        }

        cout << mindif << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<int> score(n);
            REP(i, n) cin >> score[i];
            whole(sort, score);
            int ans = INF;
            REP(i, n - 1) ans = min(ans, score[i + 1] - score[i]);
            cout << ans << endl;
        }
    }
}

C++: 
using namespace std;
typedef long long ll;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>

int main(){
	int N;
	cin >> N;
	vector<ll> ans;
	while (N!=0)
	{
		vector<ll> a;
		a.resize(N);
		for (int i = 0; i < N; i++) cin >> a[i];
		ll thismin = 1e10;
		for (int i = 0; i < N;i++) {
			for (int n = 0; n < N; n++) {
				if (n == i) continue;
				thismin = min(thismin, abs(a[i] - a[n]));
			}
		}
		ans.push_back(thismin);
		cin >> N;
	}
	for (int i = 0; i < ans.size();i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include <vector>

using namespace std;

int main(){

	int n,a[1000],ans,temp;

	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		ans=1000000;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(a[i]>=a[j]){
					temp=a[i]-a[j];
					ans=min(ans,temp);
				}
				else{
					temp=a[j]-a[i];
					ans=min(ans,temp);
				}
			}

		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>

using namespace std;

int abs(int x)
{
  if (x >= 0) return x;
  else return -x;
}

int main(void)
{
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break; 
    int a[n];
    for (size_t i = 0; i < n; i++)
      cin >> a[i];
    int min = 1000000;
    for (size_t i = 0; i < n; i++) {
      int first;
      first = a[i];
      for (size_t j = i + 1; j < n; j++) {
	int diff = abs(first - a[j]);
	if (diff < min)
	  min = diff;	
      }
    }
    cout << min << endl;
  }
  return true;

}