loops - gorskicompsci.cagorskicompsci.ca/ics2o/unit3/ppt1_loops.pdf · once upon a time there was a...

16
Loops Repetition

Upload: others

Post on 26-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

LoopsRepetition

Page 2: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

Your grade 3 teacher may have read this

book to you.

If they didn’t, I recommend

that you look it up some time.

Page 3: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR
Page 4: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR
Page 5: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR
Page 6: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR
Page 7: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

Without loops, you need to repeat the same step

over and over.

With loops,

the code is more elegant.

Page 8: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

Count is the loop stopping variable.

Page 9: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

It starts at 0 and stops before it

gets to 5.

Page 10: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

The Parts of a Loop

This is on the test and it is on

the exam.

Page 11: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

A. Initialize Loop Stopping Variable

The Parts of a Loop

A

Page 12: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

A. Initialize Loop Stopping Variable

B. Test Loop Stopping Condition

The Parts of a Loop

A B

Page 13: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

A. Initialize Loop Stopping Variable

C. Steps to repeat

B. Test Loop Stopping Condition

The Parts of a Loop

A B

C

Page 14: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

A. Initialize Loop Stopping Variable

C. Steps to repeat

B. Test Loop Stopping Condition

D. Progress to the Loop Stopping Condition

The Parts of a Loop

A B

C

D

Page 15: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR

A. Initialize Loop Stopping Variable

C. Steps to repeat

B. Test Loop Stopping Condition

D. Progress to the Loop Stopping Condition

The Parts of a Loop

A B

C

D

Page 16: Loops - gorskicompsci.cagorskicompsci.ca/ICS2O/Unit3/ppt1_Loops.pdf · Once upon a time there was a Giant. The Giant squeezed Jack and said, "TELL ME A BETTER STORY OR GRIND YOUR