Updated Condition statement (markdown)
@@ -6,7 +6,7 @@ The simplest form consists only of `if` keyword followed
|
|||||||
by condition bounded on both sides with
|
by condition bounded on both sides with
|
||||||
parentheses (`(` and `)`) and statement
|
parentheses (`(` and `)`) and statement
|
||||||
(or block of code):
|
(or block of code):
|
||||||
```
|
```php
|
||||||
if (2 > 3) println("It gonna never be displayed!");
|
if (2 > 3) println("It gonna never be displayed!");
|
||||||
|
|
||||||
# or (using block of code)
|
# or (using block of code)
|
||||||
@@ -17,7 +17,7 @@ if (2 > 3) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Just like in Java condition **must be** of `bool` type.
|
Just like in Java condition **must be** of `bool` type.
|
||||||
```
|
```php
|
||||||
# Correct examples
|
# Correct examples
|
||||||
if (true) println();
|
if (true) println();
|
||||||
if (false) println();
|
if (false) println();
|
||||||
@@ -40,7 +40,7 @@ You can use additional `else` clause which is always executed
|
|||||||
when condition is resolved to `false`.
|
when condition is resolved to `false`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```
|
```php
|
||||||
if (2 > 3) println("It gonna never be displayed!");
|
if (2 > 3) println("It gonna never be displayed!");
|
||||||
else println("but this always will be displayed");
|
else println("but this always will be displayed");
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ if (2 > 3) {
|
|||||||
Remember that only one condition statement branch (`if` or `else`)
|
Remember that only one condition statement branch (`if` or `else`)
|
||||||
can be executed in single statement. There is no possibility
|
can be executed in single statement. There is no possibility
|
||||||
to execute both clauses:
|
to execute both clauses:
|
||||||
```
|
```php
|
||||||
x = 1;
|
x = 1;
|
||||||
|
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
@@ -85,7 +85,7 @@ nor evaluators related to this construction. It is just a combination
|
|||||||
of `if` and `if-else` statements presented above.
|
of `if` and `if-else` statements presented above.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```
|
```php
|
||||||
x = 3;
|
x = 3;
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
println("x is zero");
|
println("x is zero");
|
||||||
@@ -122,7 +122,7 @@ if (x == 0) {
|
|||||||
Thanks to its tree-like construction control flow falls through all conditions.
|
Thanks to its tree-like construction control flow falls through all conditions.
|
||||||
A branch first matched branch is executed
|
A branch first matched branch is executed
|
||||||
and following conditions are not checked anymore:
|
and following conditions are not checked anymore:
|
||||||
```
|
```php
|
||||||
x = 0
|
x = 0
|
||||||
if (x == 1) {
|
if (x == 1) {
|
||||||
println(); # Condition is resolved to false
|
println(); # Condition is resolved to false
|
||||||
@@ -141,8 +141,8 @@ It means that:
|
|||||||
* in case of `A and B` expression, `B` expression will be evaluated only when `A` expression is evaluated to `true`
|
* in case of `A and B` expression, `B` expression will be evaluated only when `A` expression is evaluated to `true`
|
||||||
* in case of `A or B` expression, `B` expression will be evaluated only when `A` expression is evaluated to `false`.
|
* in case of `A or B` expression, `B` expression will be evaluated only when `A` expression is evaluated to `false`.
|
||||||
|
|
||||||
It allows you for example to keep availability-check with actual condition togheter, for example:
|
It allows you for example to keep availability-check with actual condition together, for example:
|
||||||
```
|
```php
|
||||||
function test(x: string) {
|
function test(x: string) {
|
||||||
# You are allowed to use following if-statement:
|
# You are allowed to use following if-statement:
|
||||||
if(x.length >= 5 and x.charAt(4) == "o") {
|
if(x.length >= 5 and x.charAt(4) == "o") {
|
||||||
|
|||||||
Reference in New Issue
Block a user