Podcast: Play in new window | Download
Control Structures
Here’s a breakdown of the Episode
Wiki: A control structure is a block of programming that analyzes variables and chooses a direction in which to go based on given parameters. The term flow control details the direction the program takes (which way program control “flows”). Hence it is the basic decision-making process in computing; flow controldetermines how a computer will respond when given certain conditions and parameters.
-Let’s describe that wiki statement in more human terms
– code read LINE BY LINE from top to bottom, and for the most part left to right) – CODE FLOW
– choose your own adventure… only you can have loops
– computer has a decision to make
- What are the different kinds of control structures
– IF statements
– Loops
– For
– While
– Do While
Your Homework
Please read this Java Tutorial on Control Structures to learn a bit about the actual syntax of the Java code for control structures.
If you need help, don’t hesitate to contact me at tpage@ecosim.ca.
Easy to Understand
Easy to Implement
Extremely Useful








{ 7 comments… read them below or add one }
what an awesome intro!
Are for and while the only types of loops (Not Considering the IF Statements)? Is the Do While a type of loop aswell (Not Considering Other types that may be out there)? OR……are the 2 or 3 above not types of loops at all?? What types of loops are out there? Sorry for the unending questions by the way……
forandwhileloops are both types of loops, and they are the most commonly used. Another type of loop is thedo...whileloop, but that is less often used.ifstatements are not loops, they are considered control structures.Hope that makes things nice and clear
Hi Trevor!
I have a question for you :$
Can you tell me please, why this code can’t be compiled ?! It says “Unreachable code” !
public static void main(String[] args) { while ( false ) { System.out.println("false"); } }I’m asking you, why we can’t write just the word “false” instead of a condition that produces a false result too ?!
For example:
public static void main(String[] args) { int a = 1; int b = 0; while ( a < b ) { System.out.println("1 is less than 0"); } }In this example, 1 is never less than 0, so it's false, right ?!
So, why we can write it in this way and not like the former example (while (false) { ...) ?!
Thank you soo much
Hi Trevor!
Is there any question here:$
Thanks!
Hey Durim,
Sorry I missed your question! Must have been a busy day :S
That’s actually a great question. The only answer I can give is that Java will know without any doubt that there’s no way that first “IF” statement will evaluate to true.
Whereas the second “IF” statement has the possibility of being true (via more advanced methods like reflection or Aspects)
Ahaa right, right:)
Thank you so much, I get it now!
See you in the future comments!