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>

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++)
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){
			if(a[i+1]-a[i]>=0)m = min(m, a[i+1]-a[i]);
		}
		cout << m << endl;
		cin >> N;
	}
	return 0;
}

C++: using namespace std;
using ll=long long;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
??
int main(){
????????int N;
????????cin >> N;
????????vector<ll> ans;
????????while (N!=0)
????????{
????????????????vector<ll> a;
????????????????a.resize(N);
????????????????Rep(i, N) cin >> a[i];
????????????????ll thismin = 1e10;
????????????????Rep(i, N) {
????????????????????????Rep(n, N) {
????????????????????????????????if (n == i) continue;
????????????????????????????????thismin = min(thismin, abs(a[i] - a[n]));
????????????????????????}
????????????????}
????????????????ans.push_back(thismin);
????????????????cin >> N;
????????}
????????Foreach(i, ans) out(i);
????????return 0;
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    vector<int>a;
    int ans;
    int bef;
    while(1){
    cin >>n;
    ans=INF;
    if(n==0){
        return 0;
    }
    rep(i,n){
        cin>>bef;
        a.pb(bef);
    }
    sort(all(a));
    rep(i,n-1){
        chmin(ans,a[i+1]-a[i]);
    }
    cout<<ans<<endl;
    a.clear();
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vi a(n);
    for(int i=0;i<n;++i) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    int mi = INF;
    for(int i=0;i<n-1;++i) {
      mi = min(mi, a[i+1] - a[i]);
    }
    cout << mi << endl;
  }
}

C++: #include<stdio.h>

int main(void){
 int n,a[1001],i,j,b,c,min;

 while(1){
  scanf("%d",&n);
  min=1000000;

  if(n==0){
   break;
  }
  for(i=0;i<n;i++){
   scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++){
   for(j=n-1;j>i;j--){
    if(a[j-1]<a[j]){
     b=a[j-1];a[j-1]=a[j];a[j]=b;
    }
   }
  }
  for(i=0;i<n;i++){
   c=a[i]-a[i+1];
   if(min>c){
    min=c;
   }
  }
  printf("%d\n",min);
 }
}

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

using namespace std;

int main(){
 int n;
 while(cin >> n |n){
  long long a[n],i,ans=1e7;
  for(i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  for(i=0;i<n-1;i++)ans=min(ans,a[i+1]-a[i]);
  cout << ans << endl;
 }
 return 0;
}

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

int main() {
    while (true) {
        int result=1000000;
        int n; cin >> n;
        if (n==0) break;
        vector<int> A(n);
        for (int i=0;i<n;i++) {
            cin >> A.at(i);
            if (i >= 1) {
                for (int j=0;j<i;j++) {
                    if (abs(A.at(i) - A.at(j)) < result) result = abs(A.at(i) - A.at(j));
                }
            }
        }
        cout << result << endl;
    }
}

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

using namespace std;

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

        vector<int> grade(n);
        for(int i=0; i<n; i++){
            cin >> grade[i];
        }
        
        sort(grade.begin(), grade.end());
        int dmin=1e6;
        for(int i=0; i<n-1; i++){
            dmin = min(grade[i+1]-grade[i],dmin);
        }
        cout << dmin << endl;
    }
    return 0;
}

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

int main() {
  int n;
  vector<int> a;
  vector<int> diff;

  while(cin >> n, n) {
    for(int i = 0; i < n; i++) {
      int A;
      cin >> A;
      a.push_back(A);
    }

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

    for(int i = 0; i < n-1; i++) {
      diff.push_back(a[i+1]-a[i]);
    }

    sort(diff.begin(), diff.end());

    cout << diff[0] << endl;
    a.clear();
    diff.clear();
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        int a[1000];
        rep(i,n) cin >> a[i];

        int ans = INF;
        rep(i,n){
            rep(j,n){
                if(i == j) continue;
                ans = min(ans, abs(a[i] - a[j]));
            }
        }
        cout << ans << endl;
    }
}