-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#7-Conditional_Statement.dart
More file actions
32 lines (26 loc) · 1023 Bytes
/
#7-Conditional_Statement.dart
File metadata and controls
32 lines (26 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void main() {
//<-----------Control flow statement in Dart----------->
//
//conditional Statement
//first conditional statement .
//1. condition ? expression1 : expression2
//if the condition is true evalute exp1 and return the result.
//if the condition is false evalute exp2 and return the result.
int num1 = 320;
int num2 = 54;
var result ;
num1 > num2 ? result= num1 : result= num2;
print( "this is bigger $result");
//you can make it shorter.
var result1 = num1 < num2 ? num1 : num2;
// if num1 is smaller than save the num1 value to the result1 varriable.
//else save the num2 value to the result1 varriable.
//Second conditional statement.
// 2. expression1 ?? expression2
//if the first condition is not null then evalute exp2 else exp2 will evalute.
var username;
var user = username ?? "Guest User";
print("Hey $user!");
//if this has assign a username this will say hi to the username.
//else it will print the default message.
}