Friday, July 31, 2009

C# code help...?

I need clarification on three types of loops, they all should sum the numbers from 1 to 10. like 1+2+3+4, etc...





one is a while() loop,


one is a for() loop


one is a do.. while() loop

C# code help...?
a while loop will first check it can execute. A do while loop will execute at least 1 time before it checks the condition if it can continue. A for loop will execute a set number of times from a starting number to an ending number
Reply:while(): runs till a condition is true or false


do while(): will run atleast once


for(): will run the number of times specified by you.
Reply:for(int i = 0; i %26gt; 10)


{


//code


}


Here is a for loop i forgot how to make other loops
Reply:int i;


int sum;











i = 1;


sum = 0;


while(i%26lt;=10)


{


sum += i;


i++;


}





sum = 0;


for(i=1;i%26lt;=10;i++)


{


sum += i;


}





i = 1;


sum = 0;


do


{


sum += i;


}while(i%26lt;=10);


No comments:

Post a Comment