1) What will be the output for the following code? (5 pts.) int[) array- (2,5,7,
ID: 3904972 • Letter: 1
Question
1) What will be the output for the following code? (5 pts.) int[) array- (2,5,7,10,4,6,7,11,14 Console.Hriteline): for(int ilo; icarray.Lengthi i++) Let Console.Writee)arrayl] - 2) Console.WritelineO 12) What is the main difference between a while and a for repetition statement? (S pts.) 13) What is the syntax to accomplish the following tasks? (10 pts.) a) Display the value of element of string array myStringArray with index 5 b) Initialize each of the ten elements of one-dimensional integer array myIntArray to 10 c) Total all the elements from stepb d Increase the size of array in step b to 100 elements, assuming that the size of the array was referenced to a constant size. e Initialize all elements in step d to 5Explanation / Answer
12)Answer:
For Loops allow you to run through the loop when you know how many times you'd like it to run through the problem such as for (var i; i < 10; i++); this will continually increase i untill that condition returns false, any number can replace the 10 even a variable. but it will quit once the condition is no longer being met. This is best used again for loops that you know how when they should stop.
While Loops allow you a little more flexability in what you put in it, and when it will stop such as while ( i < 10) you can also substitue in a boolean(true/false) for 10 as well as many other types of varibles.
While Loop:
The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:
initialization;
while (expression)
{
statement;
increment counter;
}
For Loop:
for statement provides a compact way to iterate over a range of values. We often call it as the "for loop" because of the way in which it repeatedly loops as long as a particular condition is satisfied.
The syntax of for loop is:
for(initialization; condition; iteration)
{
// body
}
All the three statements of while loop are combined into for loop in one statement, so it reduces LOC ( line of code).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.