Loop with For

We were practicing how to implement a loop with For. We use Pet/Dog/DogMaster classes to realize a loop. We rewrite Function say() in Dog to make it have two assumptions instead of one, so it is public String say(String aWord, int howManyTimes). aWord is what Dog wants to say, howManyTimes is just how many Times Dog wants to repeat aWord.

loop

In DogMaster, we call say (“arf!”, 10). It means we expect myDog can “arf!” for ten times.

looparf

Let’s run DogMaster, and see what’s going on in Console. Let’s count how may “arf!” there.

10timesArf.png

In the next section, we will learn some logic operators.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s