[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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
0
Nile_6670
Asked:
Nile_6670
  • 3
  • 2
1 Solution
 
snifongCommented:
What type is p?
Try:

double p;
for(p=0.05;p<1.05;p += 0.05){
   ;
   }
0
 
snifongCommented:
Also notice the p += .05
0
 
Nile_6670Author Commented:
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
0
 
Nile_6670Author Commented:
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

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

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

Featured Post

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now