184k views
3 votes
Identify examples of loop structures using comments in your code. Be sure your examples address each of the following: i. Item-based for loops ii. Index-based (range) for loops ii. While loops

User Sandymatt
by
5.0k points

1 Answer

3 votes

Answer:

item based for loop is used to iterate items in a collection .it is useful to apply some operations on item. Index based for loop is used to execute some logic repetitively. While loop also useful to execute a logic repetitively

Step-by-step explanation:

item based for loop is used to iterate items in a collection .it is useful to apply some operations on item. Index based for loop is used to execute some logic repetitively. While loop also useful to execute a logic repetitively

in c#.net , following example explains this

using system;

void main(){

String[] names=new names[20];

int counter=0;

//index based for loop

for(int i=0;i<20;i++){

console.read(names[i]);

}

//item based for loop

foreach(string s in names){

console.writeline(s);

}

//while loop

while(counter<20)

{

console.read(names[counter];

counter++;

}

}

User Aryaveer
by
4.5k points