In dart, we found two type of decision controlling instructions – if-else statements and switch statements. Here we will discuss about if-else part of dart. We put conditions into if/else-if statements. Condition gets Boolean expression which returns either true or false.

if statement

In dart, for decisions control we can use if statements.

Syntax –

Let’s see some coding examples…

Write a code, which will check integer variable ‘a’ value is 10 or not.

Code 1:

Write a code, which will check String variable ‘name’ value “microcodes” or not.

Code 2:

Nested if

It’s simply means if statement inside another If statement. When we have multiple conditions then sometime we can use nested if block. Let’s understand through an example…

Syntax –

Make a code using nested-if statements, which will response on those persons which age between 18-30.

Code 3:

Else statement

When if block’s condition not satisfies then else block get executed.

Syntax –

Let’s understand through a coding example…

Code 4:

Write a code, which checks if name will ‘bill’ then print message ‘bill invented windows’; else name will ‘linus’ then print message ‘linus invented linux kernel’.

Code 5:

Write a code, which checks a double variable ‘per’, value is 80.5 or not.

Code 6:

Else if statement

When we want to handle multiple conditions, then we can use else-if statements. Let’s understand use case of else-if statements.

Syntax –

Make a code, where it takes user’s phone number country code. There have three countries – India (91), Pakistan (92), and Bangladesh (93). According to user’s input it will print user’s country.

Code 7:

Nested if-else statement

When we want to handle multiple conditions then we can use nested if-else statements.

Let’s understand through below code example…

Code 8:

Work with Logical Operators

Till now, we have seen if, else if, else statements using relational operators like > (greater than) <(less than) >=(greater than equal) !=(not equal) etc.

Now we will perform logical operations over if-else statements.

Logical AND [ && ] – if both inputs same then output same.

Code 9:

Write a code, which will check a string name start with ‘linus’ and end with ‘torvalds’.

Code 10:

Logical OR – if at-least one input gets true then output same. This can be represented as ||

Let’s see logical OR operation, with integers of it…

Code 11:

Let’s see logical OR operation on String

Code 12: