Difference between Array and Loop.
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
Look at this example: Code: Iterating Through an Array (Visual C#)[^] Unlike single-value variable, array is a multi-value variable that stores multiple values of like nature each of which is identified by a unique index number starting from zero, you may liken it to an apartment block with a unique name (variable name) comprising many units each with a different unit number (index number). Another example, is array name 'month' that stores the names of the 12 months as its elements. This is an array of integer numbers. The first element of this array which is 1 is identified by numbers[0], the second number[1] and so on.
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
This is a loop which cycles through the same set of code (action) with different input at each cycle and thus produces different outputs for each cycle.
foreach (int element in numbers)
{
System.Console.WriteLine(element);
}Read more: 1. https://msdn.microsoft.com/en-us/library/9b9dty7d.aspx[^] 2. http://www.tutorialspoint.com/csharp/csharp_arrays.htm[^] 3. http://www.tutorialspoint.com/csharp/csharp_loops.htm[^]
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
Member 11161625 wrote:
loop is also used to store Values
No.
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
Forget values, forget types. In fact forget C# and programming in general. They have nothing to do with loops. This is a loop:
1. eat a cupcake
2. if there are more cupcakes, go to step 1Values? Types? Nope, just a list of instructions where there is a back-reference that can cause some instructions to be performed multiple times. That is the nature of a loop.
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
Hi, Loops does not store values... They can retrieve values from arrays, but it is only one use. Think about this problem: call a function 10 times. For example: write on the console 10 asterisks.. So you'll have to use the Console.WriteLine("*"); And you'll write it ten times in your code, but if I ask you to do it 1000000 times, what do you do? You'll write the same instruction 1000000 times, and if I ask you to change the * to €, you will, surely shoot me becuase you'll have to change 1000000 lines of code. Instead, if you use a loop, changements are immediate:
for (int i=0; i
Just a little curiosity: even if it is not adviced to do it,you van omit curly brackets if you construct (if, any loops, using, etc.) has only one line inside it as the example above.
Do you Understand it now :) ? Loops does not store anything, they can retrieve stored values, but they are really powerful and this isn't their only purpose as demonstrated above.
Hope this helps.
Ps: you should not post the same question twice, just reply to your own question to say that you need more information :) :)Lusvardi Gianmarco
-
Hi, EveryBody, Thanks for ur answers,it's really very helpful... But my confusion is that:- Just like array store the values of same data type, in the same way loop is also used to store value of same data type.That means i know that loop is used to avoid repetition of the code .But my question is that loop is also used to store Values??? Thanks... In Advance...
Array is a variable (in fact collection of same type of variables) to store value. while loop is process (set code) to do something. array store data but loop works on data. you can use array in loop but vise verse is not feasible (doesn't make any seance). :)