TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Help in for loop in C programming (http://forums.techarena.in/software-development/1176139.htm)

Wyvern 08-05-2009 09:39 AM

Help in for loop in C programming
 
Hello, my problem is summarized in this loop:

Code:

Dim nbbills as Integer
  nbbills = 4
  Dim nblines_f1 As Integer
  nblines_f1 = 13
  Dim nblines_f2 As Integer
  nblines_f2 = 20
  Dim nblines_f3 As Integer
  nblines_f3 = 8
  Dim nblines_f4 As Integer
  nblines_f4 = 12

  for i = 1 to nbbills
  'Id like to see in the loop the value of nblines_fi for each turn'
  next

What is the best method for achieving this?

XSI 08-05-2009 10:02 AM

Re: Help in for loop in C programming
 
I think you need a class Bill, which includes at least one property
NumberLines, then a list of bills that you can browse in your loop. This should give something like this:

Code:

List <Bill> bills = new List <Bill> ();
  // Add 1 bill
  Bill bill = new Bill ();
  bill. NumberLines = 13;
  bills. Add (bill);
  // Add 2 bill
  bill = new Bill ();
  bill. NumberLines = 20;
  bills. Add (bill);
  // Redo for bill 3 and 4.

  // Display the list
  for (int i = 0; i <bills.Count; i++)
  {
      Console.WriteLine ("The bill {0} contains {1} line(s).", i. ToString (), bill (i).NumberLines.ToString ()) ;
  }


opaper 08-05-2009 10:05 AM

Re: Help in for loop in C programming
 
You can do something like:

Code:

Dim nbbills As Integer = 4
  Dim nblines_f1 As Integer = 13
  Dim nblines_f2 As Integer = 20
  Dim nblines_f3 As Integer = 8
  Dim nblines_f4 As Integer = 12
  Dim list As Integer () = {nblines_f1 ,nblines_f2, nblines_f3, nblines_f4}

  for i = 0 to list.Length -1
  'View list (0)
  next


XSI 08-05-2009 10:07 AM

Re: Help in for loop in C programming
 
Quote:

Originally Posted by opaper (Post 4402676)
You can do something like:

Code:

Dim nbbills As Integer = 4
  Dim nblines_f1 As Integer = 13
  Dim nblines_f2 As Integer = 20
  Dim nblines_f3 As Integer = 8
  Dim nblines_f4 As Integer = 12
  Dim list As Integer () = {nblines_f1 ,nblines_f2, nblines_f3, nblines_f4}

  for i = 0 to list.Length -1
  'View list (0)
  next


If he has 1000 bills, then it will not be easy to maintain


All times are GMT +5.5. The time now is 05:44 AM.