Community Forums Archive

Go Back

Subject:Inner/outer loops
Posted by: GPD
Date:9/13/2007 8:30:51 PM


//////////////////////////////////////////////////////////////////////////////////////////////Outer

double p2 ; // Paramter for iterations
const int nPValNum2 = 16 ; // NUMBER OF P VALUES
double[] arPVal2= new double[nPValNum2] ; // C# array def
arPVal2[0] = 1 ;
arPVal2[1] = 2 ;
arPVal2[2] = 3 ;
arPVal2[3] = 4 ;
arPVal2[4] = 5 ;
arPVal2[5] = 6 ;
arPVal2[6] = 7 ;
arPVal2[7] = 8 ;
arPVal2[8] = 9 ;
arPVal2[9] = 10 ;
arPVal2[10] = 11 ;
arPVal2[11] = 12 ;
arPVal2[12] = 13 ;
arPVal1[13] = 14 ;
arPVal1[14] = 35 ;
arPVal1[15] = 16 ;


int iP2 ;

for (iP2 = 0; iP2 < nPValNum2; iP2++)
{
p2 = arPVal2[iP2]


//////////////////////////////////////////////////////////////////////////////////////////////inner Loop

double p1 ; // Paramter for iterations
const int nPValNum1 = 12 ; // NUMBER OF P VALUES
double[] arPVal1= new double[nPValNum1] ; // C# array def
arPVal1[0] = .63 ;
arPVal1[1] = .789 ;
arPVal1[2] = .89 ;
arPVal1[3] = .95 ;
arPVal1[4] = 1 ;
arPVal1[5] = 2 ;
arPVal1[6] = 3 ;
arPVal1[7] = 4 ;
arPVal1[8] = 5 ;
arPVal1[9] = 6 ;
arPVal1[10] = 7 ;
arPVal1[11] = 8 ;


int iP1 ;

for (iP1 = 0; iP1 < nPValNum1; iP1++)
{
p1 = arPVal1[iP1] ;

// processing/actions....

) // end inner loop
) // end outer loop



Is the above acceptable way to do two loops?

Message last edited on9/13/2007 8:31:36 PM byGPD.
Subject:RE: Inner/outer loops
Reply by: GPD
Date:9/13/2007 8:33:34 PM

When I add the outer loop the compiler tells me it expects another ")". If I add one, or several it still asks for more... The code runs fine with just the inner loop...

Subject:RE: Inner/outer loops
Reply by: GPD
Date:9/13/2007 8:38:34 PM


// list of client files

string[] astrClients = new string[] {

@"c:\Megatron\Megatron.wav",

@"c:\Janeco\Janeco.wav",

};



// list of prompt files.

string[] astrPrompts = new string[] {

@"c:\Prompts\Stop.wav",

@"c:\Prompts\Look.wav",

@"c:\Prompts\Listen.wav",

};



// open music bed file here, and choose a render template here.



foreach (string strFilename1 in astrClients)

{

// open strFilename1 here



foreach (string strFilename2 in astrPrompts)

{

.......

} // loop back to do the next prompt



// close strFilename1 here



} // loop back to do the next client



You handled loops and arrary's like this in a previous example. Is this a better way then the way I have done it? advantages?



Subject:RE: Inner/outer loops
Reply by: _TJ
Date:9/14/2007 1:04:48 AM

yes this is fine. It looks to me like you could move the second array out of the outer loop to the top of the function, but it sould work either way.

the problem is probably something else.

can you post the code that has the line the compiler complains about? (compiler errors have line numbers).

tj

Subject:RE: Inner/outer loops
Reply by: GPD
Date:9/14/2007 10:22:07 AM

Compiler error 0x80004005 on Line 183,5 : } expected


using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;

public class EntryPoint
{
public void Begin(IScriptableApp app)
{

//////////////////////////////////////////////////////////////////////////////////////////////Outer

double p2 ; // Paramter for iterations
const int nPValNum2 = 16 ; // NUMBER OF P VALUES
double[] arPVal2= new double[nPValNum2] ; // C# array def
arPVal2[0] = 1 ;
arPVal2[1] = 2 ;
arPVal2[2] = 3 ;
arPVal2[3] = 4 ;
arPVal2[4] = 5 ;
arPVal2[5] = 6 ;
arPVal2[6] = 7 ;
arPVal2[7] = 8 ;
arPVal2[8] = 9 ;
arPVal2[9] = 10 ;
arPVal2[10] = 11 ;
arPVal2[11] = 12 ;
arPVal2[12] = 13 ;
arPVal1[13] = 14 ;
arPVal1[14] = 35 ;
arPVal1[15] = 16 ;


int iP2 ;

for (iP2 = 0; iP2 < nPValNum2; iP2++)
{
p2 = arPVal2[iP2]


//////////////////////////////////////////////////////////////////////////////////////////////inner Loop

double p1 ; // Paramter for iterations
const int nPValNum1 = 12 ; // NUMBER OF P VALUES
double[] arPVal1= new double[nPValNum1] ; // C# array def
arPVal1[0] = .63 ;
arPVal1[1] = .789 ;
arPVal1[2] = .89 ;
arPVal1[3] = .95 ;
arPVal1[4] = 1 ;
arPVal1[5] = 2 ;
arPVal1[6] = 3 ;
arPVal1[7] = 4 ;
arPVal1[8] = 5 ;
arPVal1[9] = 6 ;
arPVal1[10] = 7 ;
arPVal1[11] = 8 ;


int iP1 ;

for (iP1 = 0; iP1 < nPValNum1; iP1++)
{
p1 = arPVal1[iP1] ;


//////////////////////////////////////////////////////////////////////////////////////////////

//DO PROCESSING CODE



//////////////////////////////////////////////////////////////////////////////////////////////

)) // Exit Loop

//////////////////////////////////////////////////////////////////////////////////////////////

}




public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}

public static IScriptableApp ForgeApp = null;

} //EntryPoint

Subject:RE: Inner/outer loops
Reply by: GPD
Date:9/14/2007 10:29:03 AM

Complier error occurs after the ")" below:



)) // Exit Loop (CLOSE TWO LOOPS)

//////////////////////////////////////////////////////////////////////////////////////////////

} // COMPILER ERROR HERE looking for another ")" many more actually...




Somehow the outer loop is not closed...

If I remove the outer loop and change to:



) // Exit Loop (CLOSE ONE LOOP)

//////////////////////////////////////////////////////////////////////////////////////////////

}



There is no errror.

Message last edited on9/14/2007 11:08:59 AM byGPD.
Subject:RE: Inner/outer loops
Reply by: GPD
Date:9/14/2007 12:15:59 PM

Moving both arrays to the top does not help.

Do I need something like this:


int i = 0;
int j;
int k;
bool BreakToOuter = false;
while (i<50)
{
j = 0;
while ((j < 75) && !BreakToOuter)
{
k=0;
while ((k < 100) && !BreakToOuter)
{
if (expression)
{
//Do something
}
else
{
//Do something else
BreakToOuter = true;
}
++k;
}
++j;
}
++i;
BreakToOuter = False;
}



I am a beginner and do not follow the above perfectly, but it seems to me that maybe this technique is relavant?

Subject:RE: Inner/outer loops
Reply by: GPD
Date:9/17/2007 6:15:37 PM

nevermind... I just learned about the difference between ) and } ( shift-0 or shift-] ) That is impossible to see on my monitor!!!!!

I guess a code editor would have told me this...

Go Back