Theif-then
statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates totrue
. Theif-then-else
statement provides a secondary path of execution when an "if" clause evaluates tofalse
. Unlikeif-then
andif-then-else
, theswitch
statement allows for any number of possible execution paths. Thewhile
anddo-while
statements continually execute a block of statements while a particular condition istrue
. The difference betweendo-while
andwhile
is thatdo-while
evaluates its expression at the bottom of the loop instead of the top. Therefore, the statements within thedo
block are always executed at least once. Thefor
statement provides a compact way to iterate over a range of values. It has two forms, one of which was designed for looping through collections and arrays.