Nothings really wrong with the loop as much as the logic needs tweaked a bit.
First thing you have a syntax error on line 5: RectangleWidth Number(2):=;
Fixing that we have a few more problems to figure out.
1) You are putting a new line \n
after each X
in the width portion of the loop. This should probably be a single X
without the new line.
2) After you output the object width, what happens to the ColumnCount
variable?
3) After you output an entire row, how do you get to a new line?
Example code with comments:
SET ServerOutput ON;
DECLARE
RectangleHeight NUMBER(2) :=5;
RectangleWidth NUMBER(2) :=9; -- FIXED SYNTAX ERROR
RowCount NUMBER(1) :=0;
ColumnCount NUMBER(1) :=0;
BEGIN
LOOP
EXIT WHEN RowCount>=RectangleHeight;
LOOP
EXIT WHEN ColumnCount>=RectangleWidth;
dbms_output.put('X'); -- DON'T PUT A NEW LINE, JUST USE PUT
ColumnCount := ColumnCount+1;
END LOOP;
ColumnCount := 0; -- AFTER A SUCCESSFUL ROW IS OUTPUT, WE RESET OUR COLUMN COUNTER
RowCount := RowCount+1;
dbms_output.put_line(null); -- JUST OUTPUTTING A BLANK LINE
END LOOP;
END;
/
And the output using 5
and 9
as inputs for height and width respectively:
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
I feel like this is homework but I always liked these kind of visual problems.