The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 foreach, C# reference material
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

CStorey

Canada
137 Posts

Posted - 04/09/2002 :  3:36:49 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I couldn't find any information in the Origin documentation about the 'foreach' statement.

Here's a reference to the complete C# (pronounced C 'sharp') specifications. It's a huge word document which is horrible to use as a refenernce, but it's better than nothing.

http://download.microsoft.com/download/VisualStudioNET/Utility/V36/W98NT42KMeXP/EN-US/csharp_36.exe



Craig Storey
Origin WebRing Member - http://g.webring.com/hub?ring=originwebring

easwar

USA
1965 Posts

Posted - 04/13/2002 :  8:07:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

It is probably not necessary to go thru all that documentation from Microsoft to understand what foreach does in Origin C.

The foreach construct allows you to loop thru the collection of all objects in a class.

Consider the following example:

void test1()
{
// Delcare worksheet object
Worksheet wks("Data1");
// Loop thru all columns of the worksheet
foreach(Column col in wks.Columns)
{
printf("Column name: %s\n",col.GetName());
}
}

The Worksheet object contains a collection of Columns, and foreach is used here to loop thru all columns in the data1 worksheet.

Let us look at another example: The Project class consists of a collection of Pages (Worksheets, Matrices, Graphs, Notes etc). A Page in turn is a collection of Layers (Graphs can have multiple layers, Worksheet has only 1 layer etc.). If the Page is a Worksheet, then the Layer then consists of a collection of Columns.

In the code below, foreach is used first to loop thru all Pages of the Project, and then to loop thru all columns of Worksheet Pages.

void test2()
{
// Declare Project to point to current project
Project proj;
// Loop thru all Pages (windows) in Project
foreach(PageBase pb in proj.Pages)
{
// Check Page (window) type. Worksheet is type = 2
int iType = pb.GetPageType();
//if Page is Worksheet, then
if(iType == 2)
{
// Cast the PageBase object to a Page object
Page pg = pb;
// Report name of the Page
printf("Page name: %s\n",pg.GetName());
// Loop thru all layers of the Page (Wks has only one layer)
foreach(Layer ly in pg.Layers)
{
// Cast the Layer object to a Worksheet object
Worksheet wks = ly;
// Loop thru all Colums of the Worksheet
foreach(Column col in wks.Columns)
{
// Report name of Column
printf(" Column name: %s\n",col.GetName());
}
}

}
}
}


You can look for more examples on using foreach by searching for it in the Origin C Help file.

Easwar
OriginLab.

P.S. This forum removes all tabs/indents and so the code examples above do not look good, but they should work fine!
Go to Top of Page

gavin.read

UK
15 Posts

Posted - 05/23/2002 :  10:20:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You might consider foreach to be a list operator. Perl and other Unix scripting languages use foreach as;

foreach (member_of_list) {

do something dead useful;

}




Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000