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 <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int u = 0; u < 300; u++)
	{
		long long n,a[1001];

		cin >> n;
		if (n == 0)
		{
			break;
		}

		long p = 1000001;

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

		sort(a,a + n);

		for (int i = 0; i < n; i++)
		{
			for (int j = 1; j < n; j++)
			{
				if (i < j && a[j] - a[i] < p)
				{
					p = 0;
					p = a[j] - a[i];
				}
			}
		}

		cout << p << endl;
	}
}

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

int n;
vector<int> a;
vector<int> s;
int main(){
  int i,j,min=10000000;
  while(1){
    cin >> n;
    if(n==0)break;
    min =10000000;
    for(i=0;i<n;i++){
      cin >> j;
      a.push_back(j);
    }
    sort(a.begin(),a.end());
    for(i=0;i<n-1;i++)if(min>a[i+1]-a[i])min = a[i+1]-a[i];
    cout << min << endl;
    while(a.size())a.pop_back();
  }
  return 0;
}

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

using namespace std;

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

}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		int a[1000];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}	
		sort(a,a+n);
		int m=10000000,x,y;
		for(int i=0;i<n-1;i++){
			if(i==0){
				m=a[i+1]-a[i];
			}
			else{
				m=min(a[i]-a[i-1],m);
			}
		}	
		cout<<m<<endl;							
	}
}

C++: #if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int n;
int a[1002];

bool input(){
  cin>>n;
  REP(i, n)cin>>a[i];
  return n;
}

void solve(){
  int d=abs(a[0]-a[1]);
  REP(i, n) {
    FOR(j, i+1, n) {
      d = min(d, abs(a[i]-a[j]));
    }
  }
  cout<<d<<endl;
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

C++: #include<stdio.h>

struct CELL
{
	int value;
	struct CELL *next;
};

int main()
{
	int n;
	struct CELL stu[1001];
	struct CELL header,*front,*back;
	int min,temp;

	while (1)
	{
		scanf("%d",&n);
		if (n == 0) break;
		header.next = NULL;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &stu[i].value);
			front = &header;
			back = header.next;
			while (back != NULL && stu[i].value > back->value)
			{
				front = back;
				back = back->next;
			}
			stu[i].next = back;
			front->next = &stu[i];
		}

		min = 1000001;
		front = header.next;
		back = front->next;
		for(int i=0;i<n-1;i++)
		{
			temp = back->value - front->value;
			if (temp < min)
				min = temp;
			front = back;
			back = back->next;
		}
		printf("%d\n",min);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e: a) cin >> e;
    sort(_all(a));

    int minDiff = a[1] - a[0];
    rep(i, n - 1){
        int diff = a[i + 1] - a[i];
        chmin(minDiff, diff);
    }

    cout << minDiff << endl;

    return 0;
}

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

int n, a[1000], ans;

int main() {
	while (true) {
		cin >> n;
		if (!n)break;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);

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

		cout << ans << endl;
	}
}

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

int main() {
    int n;
    while (true) {
        cin >> n;
        if (!n) break;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];
        int ans = 1e9;
        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;
    }
}

C++: #include <bits/stdc++.h>
#define int long long
#define INF 1e+18
using namespace std;

signed main(){
	int n;
	while(cin >> n,n){
		int a[1010],mi = INF;
		for(int i = 0;i < n;i++) cin >> a[i];
		for(int i = 0;i < n;i++){
			for(int j = i + 1;j < n;j++) mi = min(mi,abs(a[i] - a[j]));
		}
		cout << mi << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

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(all(A));
		int ans = 10000000;
		for(int i = 0; i < N - 1; i ++){
			ans = min(ans, abs(A[i] - A[i + 1]));
		}
		cout << ans << endl;
	}

	return 0;
}