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<bits/stdc++.h>
using namespace std;

int main(){
  int n,a,c;
  int minn;

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

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

    minn = abs(b[0] - b[1]);
    for(int i=0;i<n-1;++i){
      for(int k=i+1;k<n;++k){
	minn = min(minn,abs(b[i] - b[k]));
      }
    }

    delete[] b;
  cout << minn << endl;
  }

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

    minn = 1000000;

    cin >> a;
    c = a;
    for(int i=1;i<n-1;++i){
      cin >> a;
      minn = min(minn, )
    }
  }
  */
  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(){
	
	int N;
	cin >> N;
	while(N>0){
		int a[1001];
		a[1000] = 0;
		REP(i, N)cin >> a[i];
		sort(a,a+N);
		int m = 1e9;
		REP(i,N){
			m = min(m, a[i]-a[i-1]);
		}
		cout << m << endl;
		cin >> N;
	}
	return 0;
}

C++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
		int N; cin >> N;
		if (N==0) break;
		vector<int> A(N);
		rep(i,N) cin >> A[i];

		sort(all(A));
		int ans = 1e9;
		rep(i,N-1) chmin(ans,A[i+1]-A[i]);
		cout << ans << endl;
	}
}

C++: #include<cstdio>
#include<algorithm>
int n, a[1000];
using namespace std;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int diff = 100000000;
    sort(a, a + n);
    for (int i = 0; i < n - 1; i++) diff = min(diff, a[i+1] - a[i]);
    printf("%d\n", diff);
  }
}

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;i++){
			if(polong[i] - polong[i+1] < min){
				min = polong[i] - polong[i+1];
			}
		}
		cout << min << endl;
	}
}

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

using namespace std;

int main(int argc, char const *argv[]) {
    int n;

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

        sort(begin(a), end(a));

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

        cout<<diff<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main(){
	int n;
	vector<int> v(1000,0);
        int dis,diss;
	while(1){
		cin >> n;
		if( n == 0 ){
			break;
		}

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

		diss = 0;

		for(int i = 0;i < n;i++){
			for(int j = i+1;j < n;j++){
				if(v[i]-v[j] < 0){
					dis = v[j] - v[i];
				}else{
					dis = v[i] - v[j];
				}


				if( dis < diss || (i == 0 && j == 1)){
					diss = dis;
				}
			}
		}

		cout << diss << endl;
	}
}

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

int main()
{
	int a[1000];
	int n = 1;
	
	while (cin >> n) {
		int ans = 100000;
		if (n == 0)
			break;
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
		for (int i = 0;i < n - 1;i++) {
			for (int j = i + 1;j < n;j++) {
				if (ans > abs(a[i] - a[j]))
					ans = abs(a[i] - a[j]);
			}
		}
		if (ans >= 0)
			cout << ans << endl;

	}
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main(){
    while(true){
        int n; cin >> n;
        if(n == 0)break;
        vector<int> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        sort(ALL(a));
        int ans = (int)1e9;
        for(int i = 0; i < n-1; i++){
            ans = min (a[i+1] - a[i], ans);
        }
        cout << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	while (1){
		int n;
		vector<int> student;
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			int s;
			cin >> s;
			student.push_back(s);
		}
		sort(student.begin(),student.end());
		int min = 100;
		for (int i = 1; i < n; i++){
			int gap = student[i] - student[i-1];
			if (gap < min) min = gap;
		}
		cout << min << endl;
	}


	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		int a[1111];
		for(int i=0;i<n;i++)cin>>a[i];
		int ans=1e9;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				int A=abs(a[i]-a[j]);
				ans=ans<A?ans:A;
			}
		}
		cout<<ans<<endl;
	}
}