L3 - Control Flow (if-else & Loops)
L3 - Control Flow (if-else & Loops)
E mar-1
Marks >
- 39
pass
Fail
What are conditionals statements
and their use ?
↓
conditional statement
decision >
-
statement
;
-
3
3
If
=
int n 2 14 ;
it (
% = = =
)
S
S 0
.
·
Pen (Number is divisible by 7");
3
If - Else
~ if (condition (
E
3 S
if (n % 2 = =
0) odd
. 0
5 .
In (Even") ;
Vabe
S 3
ebe
3 S .
0 ·
th (6 Odd ") ;
3
If - else - if Ladder
↑ multiple conditi
a ne
if (condition)
S
statement I ;
3
ele if (condition 2)
E
statement 2 ; day
3
ebe
&
statement 3
;
3
Max of 2 numbers
int a 2 S
;
int b 2 6;
if (a >
b)
&
S o .
·
Ph (a - is manimum") ;
3
ebe
S
S . 0 .
Blu (b + "is manimum");
Y
Max of 3 numbers
is
& as = be
if(a = = b22a) =
c)
E
. Pen (a) ;
S 0 .
3
&& b )
if (b)
>
ele = a =
S 0 He
.
·
(b) ;
3
an
Ternary Operator >
- ?:
if (condition(
T
E
S -
Statement;
3 Al
abe boolean a = (n % 2 = = 0 ? tree fase)
Gi
-
-
&
statement 2 ;
Y
Watermelon problem Codeforces
https://codeforces.com/problemset/problem/4/A
What is Switch Case ?
day , .
= 1 2 3
, ,
value I
↓ -
switch (expression
-
7 if-ebe S
value
ch case value 1
-
:
T
statement
3
2
X
case value 2 :
2 -
-
Statement
break ;
Why to use Loops ?
-op
Task
↓De
a
I
point
Loop
↑
-100
For Loop
fa in ↓
test
↓
t
initialization
condition
update
part expression
3
A
1 - 2 -3 - 4 -S
For Loop
-
socintinsi
E
D ↓
fasse
While Loop
initialization
S
initialization statement
test condition
while (rest condition
E update
statement
update expression
3
#ST e
fase
int i 2 1 ; ass
true
(5)
Mi
while
S 0
.
.
Plu (i) ;
EP2
i2 i + 1
% in 2 z ,
3
i
Do-While Loop
I
initialization statement
do
&
statement
update expression
3 While (test-condition) ;
↑ I Hello i =
2 2 <
inti2
,
,
1 ; ,
Hello i 315
iz 2
2 3
do
, ,
,
in 4 4725
i2 3
,
Hello , ,
S 0
.
.
De (Hello") : is 4 Hello , ins ,
sus
,
in 6
se
icie1 ; its Hello , ,
,