yusuf
yusuf

Reputation: 3781

Missing operand in for loop

I have such a bubble sort statement;

   procedure Bubble_Sort (Data: in out List) is

      sorted: Boolean := false;
      last : Integer := Data'LAST;
      temp  : Integer;

   begin

      while (not (sorted)) loop
         sorted := true;
         for check in range Data'First..(last-1) loop
            if Data(check) < Data(check+1) then
               -- swap two elements
               temp := Data(check);
               Data(check) := Data(check+1);
               Data(check+1) := temp;
               -- wasn't already sorted after all
               sorted := false;
            end if;
         end loop;
         last := last - 1;
      end loop;

   end Bubble_sort;

I have defined 'Data' like this:

   Unsorted : constant List := (10, 5, 3, 4, 1, 4, 6, 0, 11, -1);
   Data : List(Unsorted'Range);

And the type definition of 'List' is;

type List    is array (Index range <>) of Element;

on the line

for check in range Data'Range loop

I get missing operand error. How can I solve this problem?

Upvotes: 1

Views: 989

Answers (1)

egilhh
egilhh

Reputation: 6430

remove the range keyword: for check in Data'Range loop

The range keyword is used to define ranges and subtypes (sometimes anonymous), which is not needed when you use the 'Range attribute.

Upvotes: 3

Related Questions