Difference between revisions of "Flow Control"
From Suhrid.net Wiki
Jump to navigationJump to search (Created page with " Category:OCPJP") |
|||
Line 1: | Line 1: | ||
+ | == If Statement == | ||
+ | |||
+ | * The else part is optional for an if-statement. | ||
+ | * The else belongs to the closest preceding if that doesn't have an else. Example: | ||
+ | |||
+ | <syntaxhighlight lang="java5"> | ||
+ | |||
+ | if(a > b) System.out.println("a > b"); | ||
+ | if(a > 1) System.out.println("a > 1"); | ||
+ | else System.out.println("a < 1"); | ||
+ | |||
+ | //The else belongs to if(a>1) | ||
+ | </syntaxhighlight> | ||
[[Category:OCPJP]] | [[Category:OCPJP]] |
Revision as of 00:17, 19 July 2011
If Statement
- The else part is optional for an if-statement.
- The else belongs to the closest preceding if that doesn't have an else. Example:
if(a > b) System.out.println("a > b");
if(a > 1) System.out.println("a > 1");
else System.out.println("a < 1");
//The else belongs to if(a>1)