Using For Loops

বর্গের পার্থক্য
বর্গের পার্থক্য Free Pascal ট্র্যাকে
function SquareOfSum(number : longint) : longint;
var
  i   : integer;
  acc : longint;
begin
  acc := 0;
  for i := 1 to number do
    acc := acc + i;
  result := acc * acc;
end;

function SumOfSquares(number : longint) : longint;
var
  i   : integer;
  acc : longint;
begin
  acc := 0;
  for i := 1 to number do
    acc := acc + i * i;
  result := acc;
end;

function DifferenceOfSquares(number : longint) : longint;
begin
  result := SquareOfSum(number) - SumOfSquares(number);
end;

Pascal's for loop uses := to assign the start value and the to keyword to specify the end value (inclusive). The loop variable is always incremented by 1; use downto instead of to to decrement by 1.

Local variables are declared in a var block between the function header and begin. The := operator is Pascal's assignment operator — = alone is only used for comparisons.

When a loop body is a single statement, no begin/end block is needed. acc := acc + i is the entire loop body in each case.

longint is a 32-bit signed integer. The accumulator acc is declared as longint to match the function's return type.

The result variable holds the function's return value. Assigning result := acc * acc squares the accumulated sum and sets the return value.

23 সেপ্টেম্বর 2026 · কাজে লেগেছে?

Free Pascal ট্র্যাকে বর্গের পার্থক্য অনুশীলনীর অন্য অ্যাপ্রোচগুলো

এই অনুশীলনীটি আমাদের কমিউনিটি যেভাবে অন্য ভাবেও সমাধান করেছে