Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-05-2009
Member
 
Join Date: May 2009
Posts: 3,613
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?
Reply With Quote
  #2  
Old 08-05-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
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 ()) ; 
  }
Reply With Quote
  #3  
Old 08-05-2009
Member
 
Join Date: May 2008
Posts: 2,383
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
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 08-05-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: Help in for loop in C programming

Quote:
Originally Posted by opaper View Post
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Help in for loop in C programming"
Thread Thread Starter Forum Replies Last Post
Watercooling: Single loop or Dual Loop Akolekar Hardware Peripherals 3 21-10-2011 10:52 PM
Reboot Loop in Windows 7 Reboot loop and Safe mode doesn't work mADiRAkSHii Operating Systems 4 25-01-2011 07:23 PM
Socket programming: Is any new Programming Language? Kushan Software Development 3 14-11-2009 11:13 AM
do...while loop in C programming Projectkmo Software Development 1 07-05-2009 09:52 PM
JetBrains Introduces a New Programming Paradigm With its Meta Programming System JoeFrat Software Development 3 13-12-2008 01:49 PM


All times are GMT +5.5. The time now is 09:02 PM.