This section shows us we can code normally and freely in loop blocks (including object construction and use). This is a common learning obstacle.
while (CONDITION) {
//Objects want to be in loops too!
}
Code blocks are just regular code.

Thus we can freely construct and use objects in code blocks.

Here we use a create a Rectangle during each loop to compute the sum of all the diagonals of the squares with sides 1 to 10.

It is effectively a little calculator we use within the code block.

👉🏼 Try It

📹 Video
	public void loopConstructingObjects()  {
		//Construct a rectangle during each loop
		//And use it for a calculation
		prn("\nloopConstructingObjects()");
		int
			side = 1,
			diagonalsSum = 0;
		while (side <= 10) {
			//Make a square by setting width and height equal
			Rectangle rec = new Rectangle(side, side);
			diagonalsSum += rec.computeDiagonal();
			side++;
		}
		prn("Sum Of Diagonals: " + diagonalsSum);
	}
Here we change an object during the code block.

We print the before and after the change.

👉🏼 Try It

📹 Video
	public void loopChangingObject()  {
		//Given a Rectangle -- Increase it's width
		//and height during each loop
		prn("\nloopChangingObject");
		Rectangle rec = new Rectangle(0, 0);
		int count = 1;
		prn("(Before) Rec: " + rec);
		while (count <= 10) {
			rec.setWidth(rec.getWidth() + 2);
			rec.setHeight(rec.getHeight() + 1);
			count++;
		}
		prn("(After) Rec: " + rec);
	}