Skill Sets:

Home

  1. Intro to Flash
  2. User Input
  3. Fancy Controls 1
  4. Control Flow: if
  5. Control Flow: loop
  6. Nested Structures
  7. Graphics 1
  8. Arrays
  9. Strings
  10. Mouse Movement
  11. Functions
  12. Grouping Images
  13. Graphical Support
  14. Animation
  15. Physics
  16. 2010 Grade 10 Summative showcase
  17. 2010 Grade 11 Summatives
  18. 2011 Grade 10 Summatives
  19. 2011 Grade 11/12 Summatives
  20. Sept 2011 Grade 11 Summatives
  21. Sept 2011 Grade 10 Summatives
  22. Feb 2012 Grade 10 Summatives
  23. Sept 2012 Summatives
  24. Feb 2013 Grade 12 Summatives
  25. Feb 2013 2OI Summatives
  26. Sept 2013 Summatives
  27. Feb 2014 Summatives

Nested Structures

Nesting refers to "control flow structures within control flow structures". Whether you are within a loop or an if structure, there becomes another if or loop within it.
if(condition)     {          
	if(other condition)          {             
		// more stuff         
	}          
	// stuff  
}
The matching of if ’s with else ’s is a common source of errors. When designing programs, you should be very careful to match them correctly. Here’s the rule: When an else is encountered, it is matched with the most recent if that has not yet been matched.

Indents:
Indenting control flow structures ensures that your code is readable, and more easy to fix. Notice that everything within the first “if” structure is indented. Also take note that all code within the second (nested) “if” structure is indented further. If you do not indent properly, your code will be very difficult to debug – and you will lose marks even if your code runs perfectly.

This note should have been in the first “if” note, but I did not want to muddy up the basics of “if” structures. Time to make it a bit more busy.

Logical Operators:
&& Logical AND (Conjunction)
|| Logical OR (Disjunction)
! Logical NOT: !bCondition

Wikipedia provides a great example of conjunction, and disjunction.

Relational Precedence:
Assess the following statement to find out whether it returns true of false given x=3, and y and z are 10:
if(x>5 && y>5 || z>5)

The first condition is false (x>5) and therefore the assessment of x>5 and y>5 is also false.
But, since z>5 evaluates to true, the entire statement evaluates to true.

By wrapping the later conditions is brackets so that they are evaluated first, we will get a different result:
if(x>5 && (y>5 || z>5))
Adding brackets always allows the programmer to ensure they are in control of the order of assessing relations. For clarity’s sake, the conditions in brackets should have been put at the beginning of the if statement - after all - they are being assessed first.

The rules of Boolean evaluations is as follows:
1. If compound Boolean expressions connected by ||, stop and return true at the first Boolean expression that returns true.
2. If compound Boolean expressions connected by &&, stop and return false at the first Boolean expression that returns false.