Tuesday, April 26, 2011

Lesson 20 Source Code

List of videos Lesson 20 Video
Lesson 20: The while loop part 3: break statement NOTE: for a fast copy, follow these steps in order:
  1. Click anywhere in the text box below (result will be a blinking vertical line in the text box
  2. Hit ctrl + A on the key board (the "ctrl + A" means hit Ctrl and A at the same time) (The result should be that all the text inside the text box lights up in blue)
  3. Hit Ctrl + C (Nothing significantly happens that is visible) and now its copied to the clipboard and your ready to paste it anywhere you wish
A prime number algorithm
Here is an infinite loop that we have encountered in the past. This is a bug that can be very difficult to find. We can add a condition in the while loop parameter that changes each time by using a counting variable.
Prime number algorithm
In this program, you will enter a positive Integer value for a, and it will tell you if that number is prime or not Here is the algorithm that prints off many prime numbers to the screen. Just enter an Integer value for x and it will print off that many random numbers. from 2 to x is the range of values that will be printed. a is the variable we are testing to see if its prime or not. n is the divisor that determines if it really is prime or not. Notice that when you escape from the second while loop, n has to be set back equal to 2 because in the we need to start off dividing the next number by 2 just as we have been doing for the first number.

1 comment:

  1. You are by far the best maker of tutorials on YouTube. Most everyone else just thinks that the person watching has the same knowledge of them on the subject, and their information is perceived as complete gibberish. Thanks for the vids, and keep up the good work!

    ReplyDelete