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++: #pragma warning(disable:4996)
#include<stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	while (1) {
		int n;
		int a[1001];

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

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

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


int main() {
	int n;
	int a[50000];
	cin >> n;
	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];
		}
	}
	cout << res;
}

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

int main()
{

	int n = 1;
	
	while (cin >> n) {
		if (n == 0)
			break;
		int a[1000];
		for (int i = 0;i < n;i++) {
			cin >> a[i];
		}
                
                int ans = 1000001;
		
                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]);
			}
		}
	        cout << ans << endl;

	}
	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,a[2000];
bool solve(){
	cin >> n;
	if(n == 0)
		return false;
	REP(i,n) 
		cin >> a[i];


	ll ans = 100000000;
	REP(i,n) {
		FOR(j,i + 1,n)  {
			ans = min(ans,abs(a[i] - a[j]));
		}
	}
	cout << ans << endl;
	return true;
}

int main(void) {
	while(solve());
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main(){
	int n;
	while(cin >> n && n!=0){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			cin >> v[i];
		}
		sort(v.begin(),v.end());
		int mi = 100000000;
		for(int i=0;i<n-1;i++){
			mi = min(mi,v[i+1]-v[i]);
		}
		cout << mi << endl;
	}
	return 0;
}

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

int main(void){
  while(1){
    int n; cin >> n;
    if(n == 0) break;
    vector<int> a(n);
    for(auto& _a: a){
      cin >> _a;
    }
    sort(a.begin(), a.end());
    int ans = 1000000*2;
    for(int i = 1; i < a.size(); i++){
      ans = min(ans, a[i] - a[i-1]);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,mn;
  int a[1000];
  while(1){
    cin>>n;
    if(n==0) break;
    for(int i=0;i<1000;i++){
      a[i]=0;
    }
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    sort(a,a+n);
    mn=1000000;
    for(int i=0;i<n-1;i++){
      mn=min(mn,a[i+1]-a[i]);
    }
    cout<<mn<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int abs(int i){
  if(i > 0){return i;}
  else{return -i;}
}

int main(void){
  while(1){
    int n;
    cin >> n;
    if(n == 0) {return 0;}

    int a[n];

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

    int diff;
    int ans = 500000;

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

    cout << ans << endl;
  }
}

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

using namespace std;

int main(){
  int a[1001];

  int c[1001];

  int b, mn;

  mn = 1000000;

  while(1){

    cin >> b;

    if(b == 0) break;
    
    mn = 1000000;
    
    for(int i=0;i<b;i++){
      cin >> a[i];
    }
    for(int j=0;j<b;j++){
      for(int i=0;i<b;i++){
	if(a[i] < a[i+1]) swap(a[i],a[i+1]);
      }
    }
    for(int i=0;i<b-1;i++){
      c[i] = a[i] - a[i+1];
    }

    for(int i=0;i<b-1;i++){
      if(c[i]<mn) mn = c[i];
    }

    cout << mn << endl;

  }


}

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

int main(){
	while(1){	
	int n,s[1010],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;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<numeric>
#include<queue>
#include<string>
#include<sstream>

using namespace std;

int main(void) {

  int n;
  while(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());
    int diff = 10000000;
    for(int i=1; i<n; i++){
      diff = min(diff, a[i]-a[i-1]);
    }
    cout << diff << endl;
  }



  return 0;
}










//

C++: using namespace std;
typedef long long ll;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
 
int main(){
    int N;
    cin >> N;
    vector<ll> ans;
    while (N!=0)
    {
        vector<ll> a;
        a.resize(N);
        for (int i = 0; i < N; i++) cin >> a[i];
        ll thismin = 1e10;
        for (int i = 0; i < N;i++) {
            for (int n = 0; n < N; n++) {
                if (n == i) continue;
                thismin = min(thismin, abs(a[i] - a[n]));
            }
        }
        ans.push_back(thismin);
        cin >> N;
    }
    for (auto i : ans) {
        cout << i << endl;
    }
    return 0;
}

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

int main(){


  int n,a[1000],r[50000],c=0;
  
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0; i<n;++i){
      cin >> a[i];
    }

    if(a[0]==a[1]){
      r[c] == 0;
    }else if(a[0]>a[1]){
      r[c] =a[0]-a[1] ;
    }else   r[c] =a[1]-a[0] ;
    
    for(int i=0; i<n;++i){
      if(r[c]==0) break;
      for(int k=0; k<n;++k){
	if(a[i]==a[k]){
	  if(i!=k) r[c] = a[i] - a[k];
	}else if(a[i]>a[k]){
	  if(r[c] > a[i]-a[k]) r[c] = a[i]-a[k];
	}else if(r[c] > a[k]-a[i]) r[c] = a[k]-a[i];
      }
    }
    ++c;
  }

  for(int i=0; i<c;++i){
    cout << r[i] << endl;
  }
  
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 n;
  while(cin >> n, n) {
    vector<i64> a(n);
    rep(i,0,n) cin >> a[i];

    sort(all(a));
    i64 ans = a[1] - a[0];
    rep(i,1,n) {
      ans = min(ans, a[i] - a[i - 1]);
    }
    cout << ans << endl;
  }
}