Results 1 to 6 of 6

Thread: Can we avoid using FOR loop in C++

  1. #1
    Join Date
    May 2008
    Posts
    1,137

    Can we avoid using FOR loop in C++

    I have made a program in C++. Here is a small piece of my program:

    Code:
    for (i = 1;i<=Nt;i++) 
        Matrix (i,Nt) = Vector;
    where
    Nt: integer known
    Matrix: Matrix already defined
    Vector: Vector known.


    The objective of this program is to save all lines of a matrix of the same content Vector.

    I wonder if it is possible to modify this program to eliminate the FOR loop.

  2. #2
    Join Date
    May 2008
    Posts
    188

    Re: Can we avoid using For loop in C++

    But why do you want to remove the for loop? Because in your program, if I am right, you have to have for loop.

  3. #3
    Join Date
    May 2008
    Posts
    1,137

    Re: Can we avoid using For loop in C++

    Yes, you are right, but the value of Nt is quite large and so I would like to do this without the loop. I'm in the process of achieving a very long program and so I would like not to use too much of for loops. If you have any idea for me then it will be greatly appreciated.

  4. #4
    Join Date
    May 2008
    Posts
    188

    Re: Can we avoid using For loop in C++

    If you really want then here is the program without the loop:

    Suppose, if Nt = 4:

    Code:
    Matrix (i, 1) = Vector; 
    Matrix (i, 2) = Vector; 
    Matrix (i, 3) = Vector; 
    Matrix (i, 4) = Vector;

  5. #5
    Join Date
    Nov 2008
    Posts
    2

    Re: Can we avoid using For loop in C++

    if the value of the contant ' VECTOR' is 0 then
    matrix(1,Nt)=vector;
    will work
    Last edited by invincibledj20; 12-11-2008 at 07:46 PM.

  6. #6
    Join Date
    May 2008
    Posts
    1,137

    Re: Can we avoid using For loop in C++

    Thanks invincibledj20 for that reply but I don't want any kind of loops on my program (not even while).

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. How to use For-Each Loop in PHP?
    By Bigga Lexx in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 01:16 AM
  4. Which is best for iterator: For loop or while loop
    By Leeland in forum Software Development
    Replies: 4
    Last Post: 18-01-2010, 06:03 PM
  5. Differentiate between Do-While loop and While loop
    By REDBULL in forum Software Development
    Replies: 3
    Last Post: 26-11-2009, 10:10 AM

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,715,500,542.78905 seconds with 16 queries