On Thu, 07 May 1998 23:12:03 +0200, FPL wrote:
program loop2(input, output); var i, j : integer;
begin j:=0; repeat for i:=0 to 10 do if (i div 2)=0 then begin write('*'); j:=j+1; end; writeln; until j=10; end.
Do you agree the output should be a rectangular array of 5 stars by ten, namely, something like
No. Note that for i from 0 to 10 "i div 2" will only equal 0 when i = 0 and when i = 1, otherwise, 2 will go into i at least once.
This is what I get for output: ** ** ** ** **
Which is correct, as you increment j everytime you print a star. Putting in a write(j); before you increment j may help you understand what is going on.
If you want 10 rows then you need to increment j outside of the 'if' block, which is probably most easily done by just removing the begin/end pair. [...] if (i div 2) then write('*'); j := j + 1 writeln; [...]
If you want 5 stars across, then make i go from 1 to 10 and change the test to (i mod 2).
hope this helps, -Kevin -- Kevin A. Foss --- kfoss@mint.net