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>
#include <vector>

using namespace std;

int main(){
    long long int n;
    long long int ans=1000001;

    while(cin>>n){
        if(n==0)break;
        else{
            ans=1000;
            vector<long long int> v;

            for(int i=0;i<n;i++){
                long long int a;
                cin>>a;
                v.push_back(a);
            }

            sort(v.begin(),v.end());
            
            for(int i=0;i<n-1;i++){
                ans=min(ans,v[i+1]-v[i]);
            } 
            cout<<ans<<endl;
        }
    }
}

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

using namespace std;

int n[1000]={};
long long a[1000][1000]={};
int ans = 1000000;

int main(){
    int s=0;
    while(1){
        scanf("%d",&n[s]);
        if(n[s] == 0){
            break;
        }
        for(int i=0;i<n[s];i++){
           scanf("%lld",&a[s][i]); 
        }
        s++;
    }

    int times =s;
    int sub;
    for(int i=0;i<s;i++){
        sort(a[i],a[i]+n[i]);
        for(int j=0;j<n[i]-1;j++){
            sub = abs(a[i][j] - a[i][j+1]);
            if(ans >= sub){
                ans = sub;
            }
        }
        cout << ans << endl;
        ans = 100000;
    }
    

    return 0;
}

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

int main(){
    while(1){
    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());
    //for(int i = 0; i < n; i++) cout << a[i] << " ";
    int ans = a[1] - a[0];
    for(int i = 1; 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 N;

int main()
{
    while (cin >> N)
    {
        if (N == 0)
            return 0;
        vector<int> A(N);
        int ans = (1 << 30);
        for (int i = 0; i < N; i++)
        {
            cin >> A[i];
        }
        sort(A.begin(), A.end());
        for (int i = 0; i + 1 < N; i++)
        {
            ans = min(ans, A[i + 1] - A[i]);
        }
        cout << ans << endl;
    }
}

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];
		}
		sort(a.begin(), a.end());
		int res = 10000000;
		for (int i = 1; i < n; i++) {
			res = min(res, a[i] - a[i - 1]);
		}
		cout << res << endl;
	}
	return 0;
}

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


int main(){

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

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

		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){		
				int d=abs(a[i]-a[j]);
				if(d<dif){	
					dif=d;		
				}
			}		
		}
		cout<<dif<<endl;
	}
	return 0;

}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        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;
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0) break;
    int A[1010] = {};
    rep(i,0,n) cin >> A[i];

    int min = INF;
    rep(i,0,n){
      rep(j,i+1,n){
        if(abs(A[i]-A[j]) < min){
          min = abs(A[i]-A[j]);
        }
      }
    }
    print(min);
  }


  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int x,y[x],min1=y[0],min2=y[0];
while(1){
cin>>x;
if (x=0)break;
for(int i=0;i<x;i++){
cin>>y[i];
if(y[i]<=min1){
min1=y[i];
min2=min1;}
}
cout<<min2-min1<<endl;
}
return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		int n; cin >> n;
		if (n == 0) break;
		int mind = 1000001;
		vector<int> v(n);
		for (int i = 0; i < n; i++){
			cin >> v[i];
		}
		sort(v.begin(),v.end());
		for (int i = 0; i < n -1; i++){
			mind = min(mind , v[i+1] - v[i]);
		}
		cout << mind << endl;
	}
return 0;
}

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

int main(void){
  int n, i, ans;
  int alst[1001];
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++) cin >> alst[i];
    sort(alst, alst + n);
    ans = 1000000;
    for(i=0;i<n - 1;i++) ans = min(ans, alst[i + 1] - alst[i]);
    cout << ans << endl;
  }
  return 0;
}

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

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

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

int n, a[1000];

int main() {
	cin >> n;

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

		sort(a, a + n);

		int Min = INT32_MAX;
		for (int i = 0; i < n - 1; i++) {
			if (a[i + 1] - a[i] < Min) {
				Min = a[i + 1] - a[i];
			}
		}

		cout << Min << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n, a[1001], ans=1000000;

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

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(ans>abs(a[i]-a[j]) && i!=j){
        ans = abs(a[i]-a[j]);
      }
    }
  }
  cout << ans << endl;
  ans = 1000000;
  }
  return 0;
}

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

int main(){
	while(1){	
	int n,s[1000],sa=100,h;
	cin>>n;
	if(n==0) break;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n-1;i++){
		for(int l=i+1;l<n;l++){
			h=s[l]-s[i];
			if(h<0) h=h*(-1);
			if(sa>=h) sa=h;
		}
	}
	cout<<sa<<endl;
	}	
    return 0;
}