Link to home
Start Free TrialLog in
Avatar of Nile_6670
Nile_6670

asked on

loops - is this possible????

If anyone can help I'd be most grateful

I've tried the following statement

for(p=0.05;p<1.05;p + 0.05){

but the compiler tells me that this statement will not be used.  (Probably no surprise to those in the know)

The reason I want to increment p by 0.05 is that I'm trying to write a program to simulate changes in gene frequencies, and I'd like to run the simulation with different starting frequencies, i.e. first time 0.05, second 0.10 third 0.15 and so on.  Gene frequencies always lie between 0 and 1, and rather than scan a whole load of vaules into an array I would like to increment the value of p each time the loop is run.

Thanks Neil
ASKER CERTIFIED SOLUTION
Avatar of snifong
snifong
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also notice the p += .05
Avatar of Nile_6670
Nile_6670

ASKER

float        p;

tried suggestion, but is caught in a loop somehwere.  Will have to check it now.

How does += function/what does it do?
neil.shephard@mindless.com
Thanks for the help, I've realised another way of doing this.

float p=0;
int   loopy;

for(loopy=0;loopy<20;loopy++){

p = p +0.05

}
p += .05 adds .05 to p and then assigns p .05.  In other words

(p += .05) == (p = p + .05)