In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch predication, this is always achieved by selectively altering the control flow based on some condition.
The “if” statement is most one of most frequently used conditional statements. In Easypt if
is BlockCallable
method and it has following syntax:
if (condition, {
# execute when condition is true #
});
For instance:
auto x.=("abc");
if (x.==("abc"), {
log("x is equal to abc");
});
if
also supports if-else functionality:
if (condition, {
# execute when condition is true #
}, {
# execute when condition is false #
});
For example:
auto a.=(6);
auto b.=(9);
if (a.>(b), {
log("a is greater than b");
}, {
log("a is less or equal to b");
});
Boolean
type provides few binary logical operators:
&&
(AND) performs logical and, returns new Boolean
||
(OR) performs logical or, returns new Boolean
==
(in fact NEGATED XOR) compares two logical values, returns new Boolean
!=
(in fact XOR) compares two logical values, returns new Boolean
and one unary logical operator:
!
negates value of this, returns new Boolean
See in reference: Boolean
In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
In Easypt while
is BlockCallable
method and it has following syntax:
while (condition, {
# execute while condition is true #
});
Example:
auto condition.=(true);
auto i.=(0);
while (condition, {
log(i.++());
if (i.==(10), { condition.=(false); });
});
In computer science, a for loop […] is a control flow statement for specifying iteration, which allows code to be executed repeatedly.
In Easypt for
is BlockCallable
method and it has following syntax (for
syntax is different in Easypt than in other common languages!):
for (i.comparator, someValue, change, {
# execute while i.comparator(someValue) is true after each iteration call change() #
});
Example of Int
based for
:
for (auto i.=(0).<, 10, i.++, {
log(i);
});
Example of ArrayIterator
based for
:
auto arr.=(Array());
arr.pushBack(1, 7, 3.14, "abc", "def");
for (auto it.=(arr.begin()).!=, arr.end(), it.++, {
log(it.get());
});
Example of StringIterator
based for
:
auto str.=("Hello world!");
for (auto it.=(str.begin()).!=, str.end(), it.++, {
log(it.get());
});
Oops! I didn’t tell you that String
has some functionality like Array
(both inherits from Container
, Container
inherits from Iterable
). String
has begin
and end
methods and read operator ([]
) as well.