Results 1 to 4 of 4

Thread: Help in for loop in C programming

  1. #1
    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?

  2. #2
    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 ()) ; 
      }

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    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

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

Similar Threads

  1. Watercooling: Single loop or Dual Loop
    By Akolekar in forum Hardware Peripherals
    Replies: 3
    Last Post: 21-10-2011, 10:52 PM
  2. Reboot Loop in Windows 7 Reboot loop and Safe mode doesn't work
    By mADiRAkSHii in forum Operating Systems
    Replies: 4
    Last Post: 25-01-2011, 07:23 PM
  3. Socket programming: Is any new Programming Language?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 11:13 AM
  4. do...while loop in C programming
    By Projectkmo in forum Software Development
    Replies: 1
    Last Post: 07-05-2009, 09:52 PM
  5. Replies: 3
    Last Post: 13-12-2008, 01:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,046,620.64816 seconds with 17 queries