Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

messed up loop

Status
Not open for further replies.

Khali

Programmer
Jul 16, 2009
3
PT
First of all i'll try to explain what this loop is for:
(this is only an example, i want to make the loop able to read any configuration as long as it has no closed circuits)
C o D o
\ \
b\ c\
\ d \ e
B o-------------o------------o
/ E F
a /
/
A o

Imagine this is a road, with A,B,C,D,E,F being intersections and a,b,c,d,e segments of road.
my objective is that given any road i can calculate the distance from the end node of a segment to the end point.

In this example, for instance the distance from a to F would be the length of d+e.

BolID(1) is the ID of the node i consider last (this case F)
tc(w) is the length of the w segment
PipesIDmhoEnd(w) is the ID of the end of segment w
PipesIDmhoStart(w) is the ID of the Start of segment w
ta(w) is the total length from w to F

w=1
u=1
do while (w .le. m)
do while ((IDfim(w).ne. BolID(1)))
IDfim(w) = PipesIDmhoEnd(w)
u=1
do while(IDfim(w) .ne. (PipesIDmhoStart(u)))
if(IDfim(w) .ne. BolID(1))then
u=u+1
Idfim(w)=PipesIDmhoEnd(u)
tcaux(w)=tc(u)
else
Idfim(w)=BolID(1)
tcaux(w)=0
ta(w)=0
endif
enddo
ta(w)=ta(w)+tcaux(w)
enddo
w=w+1
enddo

The code compiles well but when i try to debug it it enters a loop and can't get out.

I know this is very confusing, but if anyone could help i would appreciate.
Sorry for my English.
Thanks in advance.
 
You have 2 loops. Which of them is that?
Code:
do while (w .le. m)
  do while ((IDfim(w).ne. BolID(1)))
  ...
  end do
end do
If the loops runs forever, then one or both conditions are forever true. You need to examine which of the both conditons is it and why.

In your debugger try to set breakpoint at the first statement in the inner loop, then step thru the loop and watch the variables and/or print the values of given variables using print() or write().

 
AS far as i could find, the condition (IDfim(w).ne. BolID(1)), although the values are exactly the same is not stopping the loop. can't figure out why. I tested with print of values before and after the do while, and the value is always the same and equal on both variables.
 
What are IDfim(w) and BolID(1) ? Are that arrays or functions, show us the definitions, if possible.
 
Sorry for not properly indentate it but i haven't had time to make it readable.

I've found the problem. it had nothing to do with the code itself but with the values i was processing. with two if's it's alright now.

Thx anyway
 
Hi Khali,
it's good that you found the problem and it's ok.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top