Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Is there a "FOR/NEXT" loop problem ?


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-15-2007, 01:26 PM
Junior Member
 
Join Date: Aug 2007
Posts: 27
Question Is there a "FOR/NEXT" loop problem ?

Would you see the following script sample :
i put 2 cascaded loops and the second one must
modify the limit of the first. So :

'----------------------------------------
Sub Globals
'listbox1 declared.
'tn = 0
'tm = 0
End Sub
'--------------------------------------
Sub App_Start
Form1.Show
test
End Sub
'------------------------------------
Sub test
tn=50
tm=5
n=0
For n = 0 To tn
For m = 0 To tm
If tm<7 Then : tm = tm+1 : End If
If tn<100 Then : tn = tn+1 : End If
Next
listbox1.Add("n=" & n & " tn=" & tn & " tm=" & tm)
Next
listbox1.Add("fin ---- n=" & n & " tn=" & tn & " tm=" & tm)
End Sub
'----------------------------------

Result, (with tn and tm global or not) :
tm is modified, BUT, tn is not !
(a '51' stop is curious !)
Is it a kind of ADA-like safety limit ?
Sure, one solution is to replace first loop by a DO/WHILE,
but is it really normal ? where is my wrong ?
Thank's for help
denis
Reply With Quote
  #2 (permalink)  
Old 12-15-2007, 02:38 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,135
Default

The upper limit (or lower limit if step < 0) is only calculated when the program enters the loop.
Changing it inside the for loop will not affect the number of iterations.
Reply With Quote
  #3 (permalink)  
Old 12-15-2007, 11:52 PM
Junior Member
 
Join Date: Aug 2007
Posts: 27
Thumbs up

Right, recorded! (it was not evident)
thanks for fast answer.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with "Task.StartDate" in Outlook.dll JOTHA Bug Reports 9 09-19-2008 03:19 PM
TabControl "addControl" problem. burd27 Questions & Help Needed 4 04-20-2008 09:42 AM
Problem with Serial. ("before loop" error) jesb4ppc Questions & Help Needed 3 02-15-2008 06:41 PM
calling the device's "Programs" or "settings" screens HarleyM Questions & Help Needed 0 12-05-2007 03:59 AM
SetUpBuilder Problem - "Build Cabs first" dhillinmkewi Questions & Help Needed 1 07-27-2007 09:20 AM


All times are GMT. The time now is 06:47 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0