We've learned how to use computers to manipulate numeric data and make simple decisions using conditionals. But we haven't examined one of their most important capabilities: the ability to repeat the same task over, and over, and over again. A computer will never get tired—although it may run out of battery—and it will never make a mistake—as long as you program it correctly. So this capability is the grounds for our hope that someday computers may help eliminate many current forms of drudgery currently experienced by humans, particularly when forced to repeat mindless tasks.
Let's get started by writing using a simple loop. Assuming an Int
variable named repeat
has been declared and
initialized to a value larger than or equal to zero, write a loop that prints "Victory!" repeat
times on separate
lines. You may use any kind of loop you want! But do not modify the value of repeat
.
Stuck? You may find these lessons helpful: