Research -For Loops, For Each Loops & Dot Products

I have begin to see a pattern with these research tasks and posts. I spend a week staring at wiki, struggle to take in and process the information I’m seeing, given context in class and everything makes more sense. So from now on I plan to keep these brief with the most basic of understanding.

For Loops

A for loop appears to be a way to repeat a block of code a known amount of times. Similar to a while loop except it eventually has a condition where it terminates. Even if you as a coder aren’t sure of the amount of times the code will need to repeat to achieve the condition, it is still classed as a known amount of times and will be a for loop.

The general syntax seems to look like this:


  • Init – Declare and initialise the  control variables involved in the loop
  • Condition – If the condition you set is true, the loop runs, if false then the loop stops executing.
  • Increment – Allows the updating of control variables

As for for each loops the main difference I can see is that a for each loop are used to iterate the same action in sequence for everything in a collection.


So rather than looking for a condition to be met, you’re just repeating an action on whatever you put into the loop. I’m hoping I’ve got this right, if not I will return next week and correct my description!

Dot Products

This may be purely copying from source online, I’ll explain up to what I can understand and leave the rest for a good class explanation.

So a vector has magnitude (how long it is) and a direction. We know this from previous classes. If you have two vectors, they can be multiplied together using a dot product. I don’t know to what end but I’m sure that will be explained. The resulting number returns something called a scalar not a vector number.


To calculate we take the magnitude of the first vector, multiply it by the magnitude of the second vector and then multiply the result by cosine.

I’ll cut it there for this week and hope to make more sense of it all soon. Online the examples continue into 3D and it all gets very complex, very quick.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s