Programming)fundamentals)notes)Flow%of%Control%
• Order%of%statement%execution%–%one%statement%after%the%other%in%sequence%(linear)%• Some%programming%statements%that%modify%that%order,%allowing%us%to:%
@ Decide%whether%or%not%to%execute%a%particular%statement%@ Perform%a%statement%over%and%over,%repetitively%%
• These%decision%are%based%on%a%Boolean%expression%that%evaluates%to%true%or%false%• Order%of%statement%execution%is%called%the%flow%of%control%• Complier@%is%a%program%that%translates%source%code%into%an%executable%form%• Portable%–%means%that%a%program%may%be%written%on%one%type%of%computer%and%then%run%on%a%wide%variety%of%
computers,%with%little%or%no%modification%necessary%%
%
%
%
%
%
%
%
%
%
%
%
Conditional)statements)(also)known)as)selection)statements))
• Conditional%statement%lets%us%choose%which%statement%will%be%executed%next%%• Conditional%statements%give%us%the%power%to%make%basic%decisions%• Some%conditional%statements%in%Java%are%%
@ The%if%statement%!%used%to%create%a%decision%structure,%which%allows%a%program%to%have%more%than%one%path%of%execution%
@ The%if@else%statement!%expansion%of%if%statement%
If#Statement#
%
• If%statement%is%false%the%condition%will%be%skipped%Boolean%Expressions%
%
%
%
%
%
%
If@else%statement%
%
Logical%Operators%%
%
Logical%Not%
• Logical%Not%(also%called%logical%negation%or%logical%complement)%• If%some%boolean%condition%a%is%true,%then%!a%is%false%
Logical%AND%
%
Logical%OR%%
%
Truth%Tables%
• Shows%the%possible%true/%false%combinations%of%the%terms%
%
%
%
%
%
%
Logical%Operators%
• Conditions%can%use%logical%operators%to%form%complex%expressions%%
%
• Logical%operators%have%precedence%relationships%among%themselves%and%with%other%operators%" All%logical%operators%have%lower%precedence%than%the%relational%or%arithmetic%operators%%" Logical%NOT%has%higher%precedence%than%logical%AND%and%logical%OR%
Short%Circuited%Operators%%
• Processing%of%logical%AND%and%logical%OR%is%‘short@circuited’%• If%the%left%operand%is%sufficient%to%determine%the%result,%the%right%operand%is%not%evaluated%%
%
Block%Statements%
• Several%statements%can%be%grouped%together%into%a%block%statement%• A%block%is%delimited%by%braces:%{%…%}%• A%block%statement%can%be%used%where%a%statement%is%called%for%by%the%Java%syntax%• Several%statements%can%be%grouped%together%into%a%block%statement%delimited%by%braces%
• A%block%statement%can%be%used%wherever%a%statement%is%called%for%in%the%Java%syntax%rules%
%
%
%
%
• Block%statements%could%be%used%in%the%if@else%statement%in%the%if,%else%if%or%else%portion%%
Nested%if%statements%%
• Nested%if%statements%@%The%statement%executed%as%a%result%of%an%if%statement%or%else%clause%could%be%another%if%statement%
• An%else%clause%is%matched%to%the%last%unmatched%if%%• Braces%can%be%used%to%specify%the%if%statement%to%which%an%else%clause%belongs%
%
%
%
%
%
%
LOOPS)
The%for%Loop%
• The%for%loop%is%a%pre@test%loop%• The%for%loop%allows%the%programmer%to%initialize%a%control%variable,%test%a%condition,%and%modify%the%control%
variable%all%in%one%line%of%code%• The%for%loop%takes%the%form:%
%
%
The%for%loop%initialization%