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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

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

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

        cout << ans << '\n';
    }

    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];
		}

		int ans = a[1] - a[0];

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

		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 <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    vi vec;
    rep(i,0,n){
      cin >> l;
      vec.pb(l);
    }
    sort(all(vec));
    ll ans = INF;
    rep(i,0,vec.sz-1){
      if(abs(vec[i]-vec[i+1]) < ans){
        ans = abs(vec[i]-vec[i+1]);
      }
    }
    print(ans);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
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(a.begin(), a.end());
		vector<int> b(n - 1);
		for (int i = 1; i < n; i++) {
			b[i - 1] = a[i] - a[i - 1];
		}
		sort(b.begin(), b.end());
		cout << b[0] << endl;
	}
}

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

int main() {
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int point[1000], min=1000000;
		for(int i=0; i<n; i++) cin >> point[i];
		for(int j=0; j<n; j++){
			for(int k=j+1; k<n; k++){
				int dif = point[k]-point[j];
				if(dif<0) dif *= -1;
				if(dif<min) min = dif;
			}
		}
		cout << min << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


int main()
{
	while (1) {
		int n;
		cin >> n;

		if (n == 0) {
			return 0;
		} else {
			vi v;
			v.resize(n);
			REP(i, n) cin >> v[i];
			sort(ALL(v));
			ll ans = INF;
			REP(i, n - 1)
			{
				ans = min(ans, v[i + 1] - v[i]);
			}
			ans = min(ans, v[n - 1] - v[n - 2]);
			cout << ans << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if (n == 0) return 0;
        vector<int> V(n);
        int ans = 1000001;
        for (int i=0;i<n;i++) cin >> V[i];
        for (int i=0;i<n-1;i++){
            for (int j=i+1;j<n;j++){
                ans = min(ans,abs(V[i]-V[j]));
            }
        }
      	cout << ans << endl; 
    }
}

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    while(1) {
        int n;
        cin >> n;
        if(n==0) return 0;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = INF;
        for(int i=0; i<n-1; i++){
            int d = abs(a[i]-a[i+1]);
            ans = min(ans, d);
        }
        cout << ans << endl;
    }
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	while (N) {
		int num[100000];
		for (int i = 0; i < N; i++)cin >> num[i];
		sort(num, num + N);
		int ret = 10000000;
		for (int i = 1; i < N; i++)ret = min(ret, num[i] - num[i - 1]);
		cout << ret << endl;
		cin >> N;
	}
	return 0;
}

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

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-1);	//昇順

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

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

int main(void){
  int n;
  int a[1000]={};
  int min=1000000;
  cin>>n;
  while(n!=0){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i!=j){
	  int sa;
	  if(0>(a[i]-a[j])){
	    sa=a[j]-a[i];
	  }else{
	    sa=a[i]-a[j];
	  }
	  if(sa<min)sa=min;
	}
      }
    }
    cout<<min<<endl;
    cin>>n;
  }
}