Looping puzzle

In the course of the discussion on http://forum.servoy.com/viewtopic.php?t=4793 Maarten gave some recommended code for using foundset.getSize() within loops.

for(var i=1 ; i<= foundset.getSize() ; i++)
{
var record = foundset.getRecord(i)
record.myField = "abc"
}

I wondered whether with that setup the last record in a set would be processed or not. I ran a test with five records.

	controller.loadAllRecords();
	var size = foundset.getSize();
	controller.setSelectedIndex(1);

	for ( var i = 1 ; i <= foundset.getSize(); i++ )
	{
		var record = foundset.getRecord(i);
		var id = record.seven_id;
		var client = record.comid$sev_to_com.company_name;
	}

When it came to the last record it processed the first two lines but failed to process the last line. Therefore I changed the loop instructions to:```
for ( var i = 1 ; i <= foundset.getSize() + 1; i++ )


What's going on here? How can one be sure that all lines are executed for the last record?

Here's yet another loop structure:

controller.loadAllRecords();
controller.setSelectedIndex(1);
var size = foundset.getSize();

for ( var i = 0 ; i <= size ; i++ )
{
controller.setSelectedIndex(i);
var id = seven_id;
var client = comid$sev_to_com.company_name;
}


This one processes all lines of all records and then exits.

An answer to my own puzzle:

controller.loadAllRecords();
var size = foundset.getSize();
controller.setSelectedIndex(1);

for ( var i = 1 ; i <= foundset.getSize(); i++ )
{
    var record = foundset.getRecord(i);
    var id = record.seven_id;
    var client = record.comid$sev_to_com.company_name;
    plugins.dialogs.showInfoDialog( 'Info', client + ' Success');
}

By inserting a command of substance, not just setting another variable, as the last instruction, the above loop does indeed cycle right through, including the last record. Good to know.

Morley, are you checking this in the debugger?

the debugger indeed does not update the last line, when it is finished, but infact it does set the variable.

change the variable to columns and you will see!.

HJK:
Morley, are you checking this in the debugger?

the debugger indeed does not update the last line, when it is finished, but infact it does set the variable.

change the variable to columns and you will see!.

“Change the variable to columns”? What do you mean?

controller.loadAllRecords(); 
for ( var i = 1 ; i <= foundset.getSize(); i++ ) 
{ 
    var record = foundset.getRecord(i); 
    column1 = record.seven_id; 
    column2 = record.comid$sev_to_com.company_name; 
}

column1 and column2 are REAL columns in the database!
Try it!