Problem 2 of Project Euler is:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

This code (in Delphi 2007) finds the solution in under a second:

procedure TfrmMain.Problem2; var term1, term2, nextTerm :int64; numTotal :int64; begin term1 := 1; term2 := 2; numTotal := 2; nextTerm := term1 + term2; while nextTerm <= 4000000 do begin term1 := term2; term2 := nextTerm; if not odd(nextTerm) then inc(numTotal, nextTerm); nextTerm := term1 + term2; end; ShowMessage(IntToStr(numTotal)); end;