CSE 5J Lecture 9: Nested For Loops and User Defined Functions

94 views3 pages
20 Mar 2018
School
Course
Professor

Document Summary

Cmps 5j - lecture #9 - nested for loops and user defined functions. Just by looking at the code, you can tell that there are going to be 10 squares as the condition stops the block of code at i. The block of code draws a square when i = 0, 1, 2, ,9, thus creating 10 squares. Example 1: row of squares with for loop size(400,400); int squarewidth = width/10; for(int i = 0; i < 10; i++){ rect(i*(squarewidth), 0, squarewidth, squarewidth); A nested for loop is simply a loop within another loop. The first loop controls when the second loop ends. In example 2, the for loops create a grid as the block of code is executed again and again. Int i creates the blocks along the x axis. Int j creates the blocks along the y axis. These repeat until i and j equal 10.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents