"Il y a peu de choses qui me soient impossibles..."
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Bj Mar wrote:How should make it if I wanted it to repeat itself automatically?
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:
Bj Mar wrote:How should make it if I wanted it to repeat itself automatically?
Bj, look at Line 37 in fred's program listing. Can you describe in words what it is doing?
Bj Mar wrote:
I think It is reexecuting the program when the path is true of years == years
"Il y a peu de choses qui me soient impossibles..."
Joanne
Joanne Neal wrote:Your for loop in the other thread executes an exact number of times, so you already know the answer to this question.
You just need to use a variable in the condition (the middle part of the for loop) instead of a hard coded value.
Bj Mar wrote:Can you show me an example of how you mean?
Joanne
Paul Clapham wrote:Bj Mar,
I have merged your topic into this topic. I hope that helps.
Joanne
Joanne Neal wrote:
Bj Mar wrote:Can you show me an example of how you mean?
This is your for loop
It will execute 12 times.
If you want to execute a loop a fixed number of times based on a variable you need something like
In your original code you were trying to do this with a while loop (which is okay, although for loops are generally used for a fixed number of repetitions), but you were trying to set the value of your loop variable inside the loop instead of before it.
Bj Mar wrote:when it executes 12 times thats what i want. After it finishses executing the 12 time i want it to come back right after and give a nother 12 months, or if i type in 3 years, total of 36 months executing
Joanne
Joanne Neal wrote:
Bj Mar wrote:when it executes 12 times thats what i want. After it finishses executing the 12 time i want it to come back right after and give a nother 12 months, or if i type in 3 years, total of 36 months executing
So you need two for loops - one inside the other. The outer one loops X number of times and the inner one 12 times.
Not in the code which was posted originally. The keyword do was omitted by mistake.fred rosenberger wrote:Campbell - it's a do-while loop. . . .
Hot dog! An advertiser loves us THIS much:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|