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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  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
5 Posts 5 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, I want to know what is difference between Array and Loop.Is any one Knows,please tell me because i am little bit confuse??? Thanks... In Advance...

    W P L 3 Replies Last reply
    0
    • U User 11127370

      Hi, I want to know what is difference between Array and Loop.Is any one Knows,please tell me because i am little bit confuse??? Thanks... In Advance...

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Arrays are used to store data. A single array can contain multiple items for for example numbers. Loop then again is used for example to iterate through an array (or anything "countable"). An example :

      int[] someArray = new int[5]; // Array definition

      for (int counter = 0; counter < 5; counter++) { // Loop
      someArray[counter] = counter;
      }

      Have a look at Arrays (C# Programming Guide)[^] and for[^] or while[^]

      1 Reply Last reply
      0
      • U User 11127370

        Hi, I want to know what is difference between Array and Loop.Is any one Knows,please tell me because i am little bit confuse??? Thanks... In Advance...

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

        Two totally different things, but often used together. An array could be the floors in a building, while a loop could be like an elevator that you can use to visit those floors.

        N 1 Reply Last reply
        0
        • P PIEBALDconsult

          Two totally different things, but often used together. An array could be the floors in a building, while a loop could be like an elevator that you can use to visit those floors.

          N Offline
          N Offline
          nagendrathecoder
          wrote on last edited by
          #4

          Nice example:thumbsup:

          1 Reply Last reply
          0
          • U User 11127370

            Hi, I want to know what is difference between Array and Loop.Is any one Knows,please tell me because i am little bit confuse??? Thanks... In Advance...

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

            Hi, they are two completely different things: Array: An array is a set of homogeneous variables (I.E. they share the same type). it is declared in this way:

            YourType[] yourArray = new YourType[noitems]

            where noitems is the number of variables in the array. To access a single variable you need to use an index. This index starts from 0, not from 1, so the array indicies will go from 0 to noitems-1!!

            YourType yourArrayVariable = yourArray[yourIndex];

            Please keep in mind that if yourIndex points to a variable which does not exists in the array, a IndexOutOfRangeException will be thrown. Arrays can also have multiple dimensions:

            YourType[,] yourTable = new YourType[6,2];

            it is a declaration of a table with 6 rows and 2 columns. You can imagine a single-dimension array as a single row, a two-dimensional array as a table and a three dimensional array as a cube. There are also jagged arrays. While if you decalre your multi-dimensional array just like the code above you'll get a rectuagular table, with jagged arrays (or array of arrays), you can define your personal dimension for each element.

            YourType[][] jaggedArray = new YourType[3][];
            jaggedArray[0] = new YourType[3]; //<----- jaggedArray[0] is a single-dimensional array of type YourType
            jaggedArray[0][2] //<----- This is a single variable of type YourType

            Loops are a completely different thing.
            A loop enables you to do something repeatedly while a condition is true.

            While loops will do the instructions inside their body while a condition is true. The condition is evaluated before the loop starts and, if it is false, the loop does not start.

            while (condition){
            //do something if condition is true
            }

            There is another version of while which is the do...while loop. The only difference is that the condition is evaluated after the loop is executed. I.E. it is evaluated at the end, so the loop is executed at least once before evaluating the condition.

            do{
            //do something
            }while(condition);

            There is the for loop which is controlled by a variable which is usually an integer or, generally, a number:

            for (declaration;condition;instruction){
            //do something
            }

            for(int i = 0;i<5;i++){
            }

            The for loop has 3 different parts: the declarati

            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