|
Is the following true? 100 + 1 == 101 A good answer might be:Yes. There is no question about integers. | ||||||||
Varieties of | ||||||||
Varieties of if Statements | |
|---|---|
|
|
|
|
|
|
As you have seen, there are various ways to use
the if statement.
The statement can be used with one or two
branches, and a branch can have include one
or more statements.
The table that shows these variations.
The booleanExpression in
each of these varieties evaluates to
true or false.
Boolean expressions come in a variety of forms,
which allow you to carefully state the conditions
under which each branch will execute (see the next
chapter for this.)
The style of indenting used here leads to fewer errors than other styles you may have seen. An experiment with a group of professional programmers showed this to be true. Of course, the Java compiler ignores indenting and blank lines. Use this style unless there is a good reason not to (such as an employer that requires a different style.)
No matter which style you use, be consistent. Soon you will be able to visually see the logic of your programs. Programming and error catching will be easier.
Is the following if statement different from any
of the above?
Click Here after you have answered the questionif ( booleanExpression ){ one or more statements }else { one or more statements }