Computer Science Canada Help with Loops |
Author: | Gadd [ Sun Mar 25, 2012 12:59 pm ] |
Post subject: | Help with Loops |
Hey guys, I wanted to do a bit more practice on my looping and wanted to write this program asks the user how many multiples of 2 the user wants to see, then display it on the screen. I do know how the loops and for loops work Im just wondering how I would work with getting 2,4,6,8 on the screen if the user says 4. Thanks for the help if possible! |
Author: | Yves [ Sun Mar 25, 2012 1:34 pm ] |
Post subject: | Re: Help with Loops |
This tutorial ought to help you. You should use a for loop. How about this: try it, post it, and if it still doesn't work, somebody can help you.[/url] |
Author: | Gadd [ Sun Mar 25, 2012 1:46 pm ] | ||
Post subject: | RE:Help with Loops | ||
Thanks for the help, I also added being able to change the multiple to whatever you want. Thanks. |
Author: | Rickkwa [ Mon Mar 26, 2012 6:40 pm ] | ||
Post subject: | Re: Help with Loops | ||
Well, from that code, if num_multiples was 10, it would print all the multiples from 2 to 10 => 2, 4, 6, 8, 10. But I thought the program was to print 10 multiples of 2 => 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 So I'd change the for loop to
Also, in your for loop, exit when num_multiples = 0, doesn't have much meaning. |