C.5 if
Single-Selection Statement
Programs use selection statements to choose among alternative courses of action. For example, suppose that the passing grade on an exam is 60. The pseudocode statement
If student’s grade is greater than or equal to 60
Print "Passed"
determines whether the condition “student’s grade is greater than or equal to 60” is true. If so, “Passed” is printed, and the next pseudocode statement in order is “performed.” If the condition is false, the Print statement is ignored, and the next pseudocode statement in order is performed.
The preceding pseudocode If statement easily may be converted to the Java statement
if ( studentGrade >= 60 )
System.out.println( "Passed" );
Get Android How to Program, 3/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.