![]() ![]() I've seen a few other examples of this type of program here, but I am hoping someone can shed some light on how this one is working specifically. Why the need to nest the y variable in the loop, why is it set to 2 and why does it need to increment by one each time? Also, is there a way to get out of the loop without using the break ? I know the outer loop is checking that x is less than 100 for each iteration of the loop. I'm trying to understand what the inner loop is doing. The filter functions returns all prime numbers to the uppermost return, thereby returning the list of prime values between 2 and the passed value. I found code for a similar program online which was written using a for loop and I managed to get it to work as a while loop (took me a few days!!!). Repeat from step 2, but use 98 as the upper limit of the random number. Repeat from step 2, but use 99 as the upper limit of the random number. Since 101 is prime, 100+1 is 0 mod 101, so it is divisible by 101. Remove the elemnt from the array, making it one shorter. You can use the following JavaScript code to find prime numbers in a given range. Look up the number at this index in the array and store in your results. I managed to get a piece of code working, but I'm still not fully understanding how it works. Generate a random number between 1 and 100. ![]() ![]() I'm pretty new to programming, and I'm trying to get my head around loops.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |