Loops

SSharp S# API

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

a = [1,2,3,4,5];

 

//------------------------------------//

s = 0;

foreach (i in a)

s+=i;

 

Test.AreEqual(15, s);

//------------------------------------//

s = 0;

i = 0;

while (i < a.Length){

s += a[i];

i++;

}

 

Test.AreEqual(15, s);

//------------------------------------//

s = 0;

for(i=0;i<a.Length;i++){

s += a[i];

}

 

Test.AreEqual(15, s);

//------------------------------------//