DOC PREVIEW
TRINITY CSCI 1320 - Basic Loops

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Basic Loops9-21-20062Opening Discussion■What did we talk about last class?■Do you have any questions about the assignment?■Do you have any questions about the reading?3Repetition■Last time we decided that we wrote a little calculator and we ran into a problem when we wanted the calculator to do more than one calculation.■We got around this by having a function call itself. This is called recursion and we'll spend more time on it in the future.■Recursion is not the normal way of getting plain repetition in C. The more standard method is to use loops.4Loops in General■There are three general types of loops that occur in programming languages.Pre-test loopsPost-test loopsCounting loops■Loops also have something of a general structure that includes four elementsInitializeConditionLoop bodyIterate■The order and nature of these elements can vary. Forgetting one typically means that you have made a mistake.5Loops in C■What are the different loops that you have in the C language? What type is each one? When would you want to use each one?6Adding Loops to Code■Let's change our calculator so it uses a loop for repetition instead of recursion.■We could even write code that can “parse” prefix math expressions.■If we add a bit of logic to our ray tracing code we could make it do something interesting, like “drawing” our sphere.7Repetition through Recursion■As we saw last class, we can do repetition by having a function call itself. This is called recursion.■Recursion is an incredibly powerful tool. In C you don't normally use recursion when a loop would suffice, but there are many problems where recursion can easily do things that can't be done with loops without throwing in a lot of extra complexities.■The critical key for any recursion, is that there has to be a chance for the function to not call itself.8Minute Essay■Write a function that will sum and return the numbers read from standard input until a value of zero is read.■Remember to turn in assignment #2 by midnight tonight.■Quiz #3 will be at the beginning of next


View Full Document

TRINITY CSCI 1320 - Basic Loops

Documents in this Course
Functions

Functions

10 pages

Functions

Functions

10 pages

Graphics

Graphics

10 pages

Graphics

Graphics

11 pages

Loops

Loops

4 pages

Loops

Loops

3 pages

Strings

Strings

9 pages

Functions

Functions

10 pages

Loops

Loops

11 pages

Graphics

Graphics

11 pages

Graphics

Graphics

12 pages

Sorting

Sorting

11 pages

Sorting

Sorting

10 pages

Arrays

Arrays

10 pages

Loops

Loops

18 pages

Load more
Download Basic Loops
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Basic Loops and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Basic Loops 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?