title: ERROR: missing "LOOP" at end of SQL expression
body: <blockquote>
    <p>ERROR:  missing "LOOP" at end of SQL expression
    CONTEXT:  compilation of PL/pgSQL function "player_height_rank" near line 9</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION player_height_rank (irstname VARCHAR, lastname VARCHAR) RETURNS int AS $$ 
  
  DECLARE
  
      rank INTEGER := 0;
      offset INTEGER := 0;
      tempValue INTEGER := NULL;
      r record;
  BEGIN
  
  FOR r IN SELECT ((p.h_feet * 30.48) + (p.h_inches * 2.54)) AS height, p.firstname, p.lastname
      FROM players p
      WHERE p.firstname = $1 AND p.lastname = $2;
      ORDER BY ((p.h_feet * 30.48) + (p.h_inches * 2.54)) DESC, p.firstname, p.lastname
  
      LOOP
  
          IF r.height = tempValue then
              offset := offset + 1;
          ELSE
              rank := rank + offset + 1;
              offset := 0;
              tempValue := r.height;
          END IF;
  
          IF r.lastname = $4 AND r.lastname = $3 THEN
              RETURN rank;
          END IF;
      END LOOP;
  
      -- not in DB
      RETURN -1;
  
      END;
      $$ LANGUAGE plpgsql;
  </code></pre>