CPSC120B
Fundamentals of Computer Science I
Day 5 Notes
For Loops
Cool Computer Science Thing of the Day
Reading Questions
Quiz
Emacs Tip of the Day
- C- set mark
- C-w cut region
- M-w copy region
- C-y paste
Range
- Loops can make repetitious code easier to write
- Example of drawing a triangle
- Codes is easier to read and easier to write because it has fewer opportunities for errors
- Writing
for i in [0, 1, 2]:
is annoying for large numbers
- Use the range function instead
for i in range(3):
will run three times
- Update the triangle drawing
- The iterator variable, i, will start at 0 and end at n - 1
- What if we wanted to print 1, 2, 3 with the range function?
Lab