Getting Loopy with Iterators!



Download 457.34 Kb.
Page1/6
Date15.07.2021
Size457.34 Kb.
#151635
  1   2   3   4   5   6


Getting Loopy with Iterators!

In order to do anything really interesting, computers need to do the same things over and over. The Hi-Lo game is a good example. If you only got to guess once for a number between 1 and 100, you might lose interest in guessing. If a word processor only let you type in one word, what good would it be? If your web browser could only show one web site it wouldn't be very useful. Even if you look at a single web page, if the web browser can not load each image on the page (this is done by looping), it would be ugly or unusable. Looping is important!
One reason to loop in a computer program is to repeat some action until a certain condition is met. For example in the Hi-Lo game we loop until the game is won. Another reason to loop is when we want to do something a very specific number of times. Here is an example from Lesson Three:
print "L";

[oneMoreTime]

print "OO";

counter = counter + 1

if counter < 10 then goto [oneMoreTime]

print "PY!"

end

A fancy word for a looping command is iterator.

Download 457.34 Kb.

Share with your friends:
  1   2   3   4   5   6




The database is protected by copyright ©essaydocs.org 2023
send message

    Main page