<- Back to Main
Assignment 02 - DUE Friday, February 15th
Reading Assignment:
FOR loops ARE evil!
How evil are they actually? - Read the first and third accounts.
The Purple Book - Read up to and including the Forward. I'm going to start assigning sections of the Purple Book because people asked to learn about programming in general, as opposed to merely IDL specific programming. The Purple Book is reknowned for treating conceptual programming. Obviously there won't be any written assignments from the book.
Part 1
Introduction
This part focuses on while loops. While writing the program, think about how variable values get changed and passed around. The tricky bit is keeping track of "previous values", "current values", and "next" values, as you will see. Keep in mind the examples shown in class:
dice.pro
blackjack.pro
The Assignment:
Do numbers 3 and 4 on the page linked below.
Click here for worksheet: hw1.html
Part 2
Introduction
This part focuses on math and arrays. The tricky bit is thinking about your code in terms of math. The code is simple but its tricky to get all of the math right. Also think about data types, and how integers can help you. Also remember the range of numbers that a certain data type can have. Keep in mind the examples shown in class:
hangman.pro
test.pro
The Assignment:
Do number 1 on the page linked below.
Click here for worksheet: hw2.html
Then write the same program but using a while loop instead of arrays. Now, set BIN=1, MIN=0, MAX=1e6 and run each of your programs. What happens? Which program succeeds, and which fails?
HINTS:
For #3: WHILE loop and conditionals. Also note how blackjack.pro passes variables into a loop, changes them in the loop and then passes them out again.
For #4: See string manipulation.
For #1: Use findgen(). Also try writing out the math on paper before you program. Think about the range you want your array to have, and also the interval between each point. Thinking of an equation to do this will make your coding much easier.
Update: Paul Higgins - January 24, 2007 - UG Astro, Department of Astronomy, University of California at Berkeley