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++: // 1608
#include <iostream>
#include <vector>
using namespace std;

void MergeSort(vector<int> &A, int left, int right){
	
	if(left >= right)
		return;

	int mid = left+(right-left)/2;
	MergeSort(A, left, mid);
	MergeSort(A, mid+1, right);

	vector<int> B,C;
	
	for(int i=left;i<=mid;i++)
		B.push_back(A[i]);
	for(int j=mid+1;j<=right;j++)
		C.push_back(A[j]);
	
	int i=0, j=0;
	for(int k=left;k<=right;k++){
		if(i == B.size())
			A[k] = C[j++];
		else if(j == C.size())
			A[k] = B[i++];
		else if(B[i] <= C[j])
			A[k] = B[i++];
		else
			A[k] = C[j++];
	}
}

int main(){
	
	while(1){
		int n, num;
		vector<int> grade;
		cin>>n;

		if(n == 0)
			break;

		for(int i=0;i<n;i++){
			cin>>num;
			grade.push_back(num);
		}

		MergeSort(grade, 0, n-1);

		int dif = grade[1]-grade[0];
		for(int i=1;i+1<n;i++)
			if(grade[i+1]-grade[i] < dif)
				dif = grade[i+1]-grade[i];

		cout<<dif<<endl;
	}

	return 0;
}

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

int main() {
	int n;
	while (std::cin >> n && n) {
		std::vector<int> a;
		int minLength = 10000000;

		//????????????????????\???
		for (int i = 0; i < n; i++) {
			int b;
			std::cin >> b;
			a.push_back(b);
		}

		std::sort(a.begin(), a.end());

		//????°???????????±???????
		for (int i = 0; i < a.size() - 1; i++) {
			minLength = std::min(a[i + 1] - a[i], minLength);
		}

		std::cout << minLength << std::endl;
	}
	return 0;
}

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

int main(){
    
while(1){
    
    int n;
    cin >> n;
    if(n==0) break;
    vector<int> vec(n,0);
    vector<int> comp(n-1,0);
    for(int i=0;i<n;i++){
        cin >>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<n-1;i++){
        comp.at(i)=vec.at(i+1)-vec.at(i);
    }
    sort(comp.begin(),comp.end());
    cout << comp.at(0) << endl;
}
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,min;
	cin>>n;
	min=1000000;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n-1;i++){
		if(min>a[i+1]-a[i]){
			min=a[i+1]-a[i];
		}
	}
	cout<<min<<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 0;

}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INT 1000000000

int a[2000];

int main() {
  while(1) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    REP(i, n)
      scanf("%d", &a[i]);
    int min = INT_MAX;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        if (min > abs(a[i] - a[j]))
          min = abs(a[i] - a[j]);
      }
    }
    printf("%d\n", min);
  }
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1e18 : 1e9;
const int MOD = 1000000007;
const long double EPS = 1e-8;

int n, a[1010];

int main() {
	while (cin >> n, n) {
		rep (i, n) cin >> a[i];
		int mini = INF;
		rep (i, n) range (j, i + 1, n) mini = min(mini, abs(a[i] - a[j]));
		cout << mini << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#define SEISEKI 10000000

using namespace std;

int main() {
	while (1) {
		int n;
		int ans=SEISEKI;

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

		sort(a, a+n);	//昇順

		for (int i = 0; i< n; i++) {
			ans = min(ans,a[i]-a[i - 1]);
		}
		cout << ans<<endl;
	}
	return 0;
}

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

int main(void) {
    int n;
    int diff;
    int diff_min;
    while (1) {
        std::cin >> n;
        if (n == 0) {
            break;
        }
        std::vector<int> score(n);
        diff_min = 1e09;
        for (int i = 0; i < n; i++) {
            std::cin >> score[i]; 
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                diff = score[i] - score[j];
                if (diff < 0) {
                    diff *= (-1);
                }
                if (diff < diff_min) {
                    diff_min = diff;
                }
            }
        }
        std::cout << diff_min << std::endl;
    }

    return 0;
}

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

using namespace std;

int main(){
	long n, tmp;
	while(cin >> n, n){
		vector<long> polong;
		long min = 1000001;
		long res;
		for(long i=0;i<n;i++){
			cin >> tmp;
			polong.push_back(tmp);
		}
		sort(polong.begin(),polong.end(),greater<long>());

		for(long i=0;i<n-1;i++){
			if(polong[i] - polong[i+1] < min){
				min = polong[i] - polong[i+1];
			}
		}
		cout << min << endl;
	}
}

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

using namespace std;

int main()
{
  int N, A[1000];
  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; i++) scanf("%d", A + i);
    int ret = 1e9;
    for(int i = 0; i < N; i++) for(int j = 0; j < i; j++) ret = min(ret, abs(A[i] - A[j]));
    printf("%d\n", ret);
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; 
	while (cin >> n, n)
	{
		vi v(n); cin >> v;
		int ans = 1e9;
		REP(i, n)REP(j, i)
		{
			chmin(ans, abs(v[i] - v[j]));
		}
		cout << ans << endl;
	}
	return 0;
}