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 <algorithm>
using namespace std;
int main() {
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		int student[n];
		for(int i = 0; i < n; i++){
			cin >> student[i];
		}
		std::sort(student,student + n);
		int defference[n-1];
		for(int i = 0; i < n-1; i++){
			defference[i] = student[i+1] - student[i];
		}
		std::sort(defference, defference + (n-1));
		cout << defference[0] << endl;
  		
	}
return 0;
}

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


int main() {

	vector<int> result;
	while (true)
	{
		
		int n;
		int a[50000];
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		sort(a, a + n);
		int res = 1000000000;
		for (int i = 0; i < n - 1; i++) {
			if (res > a[i + 1] - a[i]) {
				res = a[i + 1] - a[i];
			}
		}
		result.push_back(res);
		
	}	

	for (auto a: result) {
		cout << a << endl;
	}

}

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  int n;
  while(cin >> n, n){
    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 = 0; j < n; j++){
        if(i != j){
          ans = min(ans, abs(a[i]-a[j]));
        }
      }
    }
    cout << ans << endl;
  }
}

C++: 
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;
int i,j;


int main() {
    int n;
    cin>>n;
    int a[10000];
    rep(i,n)
    cin>>a[i];
    sort(a,a+n);
    int m=1000;
    rep(i,n-1)
    m=min(m,abs(a[i]-a[i+1]));
    cout<<m<<endl;
    return 0;
}

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

int main(){
    int n,dif;
    while(cin>>n){
if(n==0)break;
        dif=1000000;
        int a[1000];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
     sort(a,a+n);
for(int i=0;i<n-1;i++)
        if(max(a[i]-a[i+1], a[i+1]-a[i])<dif)dif=max(a[i]-a[i+1], a[i+1]-a[i]);

cout<<dif<<endl;
    }
    return 0;
}

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

int main(){
  int n;
  while(cin>>n,n){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int res=1e9;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	res=min(res,abs(a[i]-a[j]));
      }
    }
    cout<<res<<endl;
  }
  return 0;

}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    int a[1010];
    for(;;) {
        cin >> n;
        if(n == 0) break;
        rep(i, n) cin >> a[i];
        int ans = abs(a[1] - a[0]);
        rep(i, n) {
            rep(j, n) {
                if(i == j) continue;
                ans = min(ans, abs(a[i] - a[j]));
            }
        }
        cout << ans << endl;
    }
	return 0;
}

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

using namespace std;

int main() {
    int n, a[1001];
    int ans;

    while (true) {
        cin >> n;
        if (!n) { break; }

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

        ans = 1e8;

        for (int i = 0; i < n-1; 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;
int main(){
  int n;
  while(cin>>n,n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++)
      cin>>a[i];
    sort(a.begin(), a.end(),greater<int>() );
    int df=1000001;
    for(int i=0;i<n-1;i++){
      if(df>=a[i]-a[i+1]){
        df = a[i]-a[i+1];
      }
    }
    cout<<df<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<int> deq;
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            int min=1000000;
            for (int j=0;j<deq.size()-1;j++) {
                for (int k=j+1;k<deq.size();k++) {
                    if (abs(deq[j]-deq[k])<min) {
                        min=abs(deq[j]-deq[k]);
                    }
                }
            }
            cout<<min<<endl;
        }
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int n, a[1000005];

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

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

#define vi vector<int>
#define pb push_back

typedef long long ll;
using namespace std;



int main(){
    int n;
    while(cin >> n,n) {
        int tmp;
        vi a;
        rep(i,n){
            cin >> tmp;
            a.pb(tmp);
        }
        sort(a.begin(),a.end());
        int mn = abs(a[1] - a[0]);
        rep(i,n) mn = min(mn,abs(a[i + 1] - a[i]));
        cout << mn << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n, a[1009];
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> a[i];
		sort(a, a + n);
		int ret = 1999999999;
		for (int i = 1; i < n; i++) ret = min(ret, a[i] - a[i - 1]);
		cout << ret << endl;
	}
	return 0;
}