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 12-11-2008
Member
 
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.
Reply With Quote
  #2  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 186
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.
Reply With Quote
  #3  
Old 12-11-2008
Member
 
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.
Reply With Quote
  #4  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 186
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;
Reply With Quote
  #5  
Old 12-11-2008
Member
 
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.
Reply With Quote
  #6  
Old 12-11-2008
Member
 
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).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Can we avoid using FOR loop in C++"
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
How to use For-Each Loop in PHP? Bigga Lexx Software Development 5 06-03-2010 01:16 AM
Which is best for iterator: For loop or while loop Leeland Software Development 4 18-01-2010 06:03 PM
Differentiate between Do-While loop and While loop REDBULL Software Development 3 26-11-2009 10:10 AM


All times are GMT +5.5. The time now is 10:50 PM.