Skip to content

Commit 12a794e

Browse files
12.1. If: Added example of single statement if block
1 parent 7f43e1a commit 12a794e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/branching_logic/if.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ if (age < 25) {
3838

3939
If this condition evaluates to `false`, then the code inside of `{` and `}`
4040
will not run.
41+
42+
NOTE: If you have only one statement, you do not need to put code inside of `{` and `}`. Moreover, the remaining lines will not be considered part of the if block.
43+
44+
```java
45+
~void main() {
46+
int age = 20;
47+
if (age < 25)
48+
IO.println("You are too young to rent a car!"); // If condition evaluates to true
49+
IO.println("Bye bye"); // Always printed
50+
~}
51+
```

0 commit comments

Comments
 (0)