Thread Subject:
Advantages of for and while loops?

Subject: Advantages of for and while loops?

From: Jeremy

Date: 15 Apr, 2010 22:15:39

Message: 1 of 1

Say you have a function f(x) that you wish to integrate in steps from a to b.

Two ways of writing this program would be:

syms x;
i=1;
while i<=10
    I=int(f(x),i-1,i)
    i=i+1;
end

syms x;
for i=1:10
    I=int(f(x),i-1,i)
end

Obviously the while loop is more code to write, but will it effect the efficiency of the program? I'm thinking that the while loop is going to take more time to compute, can anyone confirm this? What's the advantages of using a while loop in a situation like this, if any?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us