Loop stopping short

Reply

Join Date: Sep 2005
Posts: 6
Reputation: platinum is an unknown quantity at this point 
Solved Threads: 0
platinum platinum is offline Offline
Newbie Poster

Loop stopping short

 
0
  #1
Sep 11th, 2005
Hi everyone!

I have this loop which just wont complete. My code is:

begin
a:=1;
repeat
b:=1;
repeat
write('element ', a, ',', b, ' = ');
readln(mat[a, b]);
b:=b+1;
until b>n;
a:=a+1;
until a>n;
end;


a, b and n are all declared as integers. This is used to enter the elements of a n by n matrix into the program, a being rows and b columns. The application completely shuts downs after I enter the [n, 1] element and I'm going crazy trying to figure out why!

I'm not asking for a "do this" answer, but some pointing in the right direction would be much apreciated.

Pt
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 6
Reputation: platinum is an unknown quantity at this point 
Solved Threads: 0
platinum platinum is offline Offline
Newbie Poster

Re: Loop stopping short

 
0
  #2
Sep 13th, 2005
ok, got it!

Because the matrix is a dynamic array, indexes run from 0 through n-1 instead of 1 through n. Adjustment of a and b values fixed this.

Thanks for looking at it.

Pt
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC