quick question about loops

quick question about loops

Page 1 of 1

5 Replies - 1031 Views - Last Post: 04 October 2009 - 02:45 PM Rate Topic: -----

#1 putha-nee   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 168
  • Joined: 04-October 09

quick question about loops

Posted 04 October 2009 - 02:23 PM

I am trying to put together a for loop that uses pre-defined variables so that the for loop can automatically add the sum of what it is I want it to do.

for (weight = 11; weight <= weight_limit; weight++)]
{
weight = weight * 0.18;
}



What I want to do is for the program to start from 11 and go to weight_limit (which is already instantiated) and for java to calculate the total automatically.

i.e. sum of 11*0.18 + 12*0.18+...,weight_limit*0.18

I am guessing you guys will correct the loop by indexing it but some help in that regard would be highly appreciated unless you guys know of a better method

Is This A Good Question/Topic? 0
  • +

Replies To: quick question about loops

#2 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: quick question about loops

Posted 04 October 2009 - 02:25 PM

weight += weight * 0.18;



will keep on adding to the current weight and in the end will output the total weight
Was This Post Helpful? 1
  • +
  • -

#3 putha-nee   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 168
  • Joined: 04-October 09

Re: quick question about loops

Posted 04 October 2009 - 02:33 PM

View Postmostyfriedman, on 4 Oct, 2009 - 01:25 PM, said:

weight += weight * 0.18;



will keep on adding to the current weight and in the end will output the total weight


Thanks a lot man, appreciate it.

Hey, would you mind if I tried to contact you via email or do you have msn or yahoo aim by any change mate?

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: quick question about loops

Posted 04 October 2009 - 02:36 PM

depends, i don't really like people to ask me about programming or homework questions via email because I have my other things that keep me busy other than that its ok :)
Was This Post Helpful? 0
  • +
  • -

#5 putha-nee   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 168
  • Joined: 04-October 09

Re: quick question about loops

Posted 04 October 2009 - 02:37 PM

View Postmostyfriedman, on 4 Oct, 2009 - 01:36 PM, said:

depends, i don't really like people to ask me about programming or homework questions via email because I have my other things that keep me busy other than that its ok :)


Just if i had any minor simplistic questions. I'd be sure not to take up much of your time if you wouldn't mind
Was This Post Helpful? 0
  • +
  • -

#6 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: quick question about loops

Posted 04 October 2009 - 02:45 PM

just post any questions you have on the forum, it will get more attention and you will get different opinions and approaches to solve your problem, you will benefit yourself and others this way
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1