
-----------------------------------
MossyMossy
Tue Nov 10, 2009 9:37 am

Starting value. to an ending value.
-----------------------------------
I need to create a program that prompts the user for 2 values a start value and a end value. The program must print all the numbers from the start value to the end, with it increasing by 2's The program must employ a loop structure of some sort.



var number : int
var endnumber : int

put "Please enter a value"
get number
put "Please enter an ending value"    
get endnumber

loop

put number + 2

    exit when number = endvalue
end loop

-----------------------------------
B-Man 31
Wed Nov 18, 2009 7:43 pm

Re: Starting value. to an ending value.
-----------------------------------
for loops are not user controlled
Could you elaborate on such a claim?

ok, what i said is generally true, unfortunately i was wrong in this case as i figured out but let me still explain to you what i mean.

When a person decides to use a for loop the programmer decides exactly when to exit, after x amount of repetitions, so it makes no sense to use it when you want it to be user controlled, for instance, the user wants to click something as many times as they want, and it will only exit when finished. you need a user controlled loop (AKA regular loop) rather than a programmer controlled loop (for loop). I hope that clears thing up :D

-----------------------------------
TheGuardian001
Wed Nov 18, 2009 7:58 pm

Re: Starting value. to an ending value.
-----------------------------------
When a person decides to use a for loop the programmer decides exactly when to exit, after x amount of repetitions, so it makes no sense to use it when you want it to be user controlled

[code]
var x : int
put "Enter a value greater than 1..."
get x

for i : 1 .. x
put "User defined for loops are AWESOME!"
end for
[/code]

So long as either you or the user knows how many times it will run through (for example counting to a certain user inputted value), for loops will work just as well as a standard loop, and will even automate the exit condition. The programmer might decide when it will exit, but they don't have to use a constant value.

-----------------------------------
B-Man 31
Wed Nov 18, 2009 9:59 pm

Re: Starting value. to an ending value.
-----------------------------------
yeah i definitely understand that but i as just saying, in general it is better to have loops if it is user defined and for loops if it is not.

-----------------------------------
Tony
Thu Nov 19, 2009 1:34 am

Re: Starting value. to an ending value.
-----------------------------------
the user wants to click something as many times as they want, and it will only exit when finished. you need a user controlled loop (AKA regular loop)
[code]
for ( ;; ){
   if (user_done_clicking)
      break;
}
[/code]
 :wink:

-----------------------------------
belarussian
Thu Nov 19, 2009 10:10 am

RE:Starting value. to an ending value.
-----------------------------------
ya but you could also do a for loop and it will be user controled

May not be 100% correct i am doing this in a sec
%%%%%%

for endclicks : 0..amountofclicks
WILL FINISH LATER
