looping problem

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

looping problem

Post by suhailkaleem »

hi!
i know the belwo code is in asp can be easily be converted to php , but that does not make much difference .


<%
n=0
'j=1
for i=0 to j

if n<>90 then
j=j+1
response.write "<br>j= "&j
end if
n=n+1
response.write "<br>n= "&n
next

'This must loop 90 times but it loops 1 time why is that ?
'anyhelp ?
%>

suhailkaleem
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Are you looking for help in having this converted to PHP or do you want help with the ASP?

Mac
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

Post by suhailkaleem »

twigletmac wrote:Are you looking for help in having this converted to PHP or do you want help with the ASP?

Mac

n=0
'j=1
for i=0 to j

if n<>90 then
j=j+1
response.write "<br>j= "&j
end if
n=n+1
response.write "<br>n= "&n
next

'This must loop 90 times but it loops 1 time why is that ?
'anyhelp ?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

OK, if this question is not about PHP then it does not belong in the PHP forum.

If you want help with ASP in future please post in the Miscellaneous forum (to which this message has been moved).

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It's been a while that I used ASP and no IIS is as hand right now.
But afaik then end-value of an for-loop is calculated only once.
You may change the counter but not the loop-edges.
To be sure try this one

Code: Select all

Function getVal(j As Integer) As Integer
  getVal = j
  response.write "getVal called<br>"
End Function

n = 0
j = 10
For i = 0 To getVal(j)
  If n <> 90 Then
    j = j + 1
  End If
  n = n + 1
Next
I'm quite sure getVal called is printed only once
( was as Integer as function type declaration necessary/valid in ASP? )
Post Reply