Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Difference between Array and Loop.

Difference between Array and Loop.

Scheduled Pinned Locked Moved C#
questiondata-structures
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11127370
    wrote on last edited by
    #1

    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...

    P P L L S 6 Replies Last reply
    0
    • U User 11127370

      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...

      P Offline
      P Offline
      Peter Leow
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      • U User 11127370

        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...

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Member 11161625 wrote:

        loop is also used to store Values

        No.

        1 Reply Last reply
        0
        • U User 11127370

          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...

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          An Array is a block of memory that holds a set of data. It is where information is stored. A Loop is a set of instructions which may act upon that (or any other) data. There is no similarity between the two, they are totally different in every way.

          1 Reply Last reply
          0
          • U User 11127370

            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...

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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 1

            Values? 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.

            1 Reply Last reply
            0
            • U User 11127370

              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...

              L Offline
              L Offline
              LLLLGGGG
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • U User 11127370

                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...

                S Offline
                S Offline
                Santosh K Tripathi
                wrote on last edited by
                #7

                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). :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups