Loop hi nested a nih lem loh chuan a har hranpa em em lo va, nested a nih a, condition a tam hian lu a tihai thei viau bawk. Chuvangin loop kalkawng zawng zawng nen lam tilangin tutorial Online lama chhim tur awm lem lo kalphung dang deuhvin sawifiah kan tum ang. Tun tumah hian Vanilla JS for loop hmangin ‘A’ siamchhuah dan hmangin Loop (kalkualna tiin zo tawng chuan ka dah mai a) kan zir dawn a ni. Kan siamchhuah tur chu lo en phawt ila:
let str = "\n";
🔪🔪🍏🍏🍏🔪🔪
🔪🍏🔪🔪🔪🍏🔪
🔪🍏🔪🔪🔪🍏🔪
🔪🍏🍏🍏🍏🍏🔪
🔪🍏🔪🔪🔪🍏🔪
🔪🍏🔪🔪🔪🍏🔪
🔪🍏🔪🔪🔪🍏🔪
Sawifiahna:
Column(tlar phei) leh Row(tlar tung) pasarih ve ve kan nei a. Apple leh chemte rem dan tur a hnuaia mi ang hian i lo sawifiah dawn teh ang.
- row value (hlutna) hi 1 kan neih tir ang a, 7 a tlin thlengin kan kalkual(loop) tir ang, .
JS for loop code hmanga kan dah chuan:
for(let row = 1; row<=7; row++){
//vawi 7 kan kalkual ang.
} - column value pawh hi a tirah 1 kan neihtir ang a, 7 a tlin thlengin kan kalkual tir ang. Column hi row kan kalkual (loop) tir apiangin vawi 7 kan kalkual (loop) tir ve dawn a ni. Chuvangin row vawi khat kalkual apiangin column vawi 7 kan kalkual (loop) tir ve dawn tihna a nih chu.
for(let column= 0; column<=6; column++){
//vawi 7 kan kalkual ang.
} - 1st Row & 7 Columns: Row kalkualna(loop) hmasa berah chemte print chhuak tur chuan column kan ngaihtuah tel a ngai a. Row vawi khat kalkual apiangin column vawi 7 kalkual a ngaih bawk avangin a lema kan hmuh ang hian column vawi khatnaah leh vawi hnih kalkualnaah chemte print chhuah a ngai dawn a, a vawi 3na 4na leh 5-naah erawh chuan apple kan dah a ngai a. Voi 6na leh 7na ah chuan chemte bawk kan dah a ngai dawn a ni. A code-in lo dah dawn ta ila:
if( ( (column == 1 || column == 2) && row==1) || ((column==6 || column==7) && row==1)){
//column hlutna chu 1 or 2 or 6 or 7 a nih a, row pakhat chauh a nih chuan
// str-ah chemte dah tur
//Column 1 & 2 = 🔪🔪
//Colomn 6 & 7 = 🔪🔪
}else{
//Column 3, 4 & 5 = 🍎 🍎 🍎
}
column lo remkhawm ta ila:
1 2 3 4 5 6 7
🔪 🔪 🍎 🍎 🍎 🔪 🔪 - 2nd Row & 7 Columns: Row
vawi hnih kalkualnaah chuan 2 column leh 6th column-ah chauh apple kan dah a ngai a. Condition chi hrang hrangin a siam theih ang. A hnuaia js code hi han bel chiang phawt ila:
if( (row==2 && column==2) || (column == 6 && row==2)){
//column 2 = 🍎
//column 6 = 🍎
}else{
//column 1, 3, 4, 5, 7 = 🔪,🔪,🔪,🔪,🔪
}
Hmun khatah column indawt danin lo rem leh ta ila:
1 2 3 4 5 6 7
🔪 🍎 🔪 🔪 🔪 🍎 🔪 - 3rd Row pawh a chunga mi ang bawk hian a condition siam tur a ni a.if( (row==3 && column==2) || (column == 6 && row==3)){
//column 2 = 🍎
//column 6 = 🍎
}else{
//column 1, 3, 4, 5, 7 = 🔪,🔪,🔪,🔪,🔪
}Hmun khatah column indawt danin lo rem leh ta ila:
1 2 3 4 5 6 7
🔪 🍎 🔪 🔪 🔪 🍎 🔪 - 4th Row thungah chuan a lema kan hmuh ang hian tlemin kan condition kan her danglam a ngai dawn a niif( (row==4 && column==1) || (column == 7 && row==4)){
//column 1 = 🔪 //column 7 = 🔪
}else{
//column 2, 3, 4, 5, 6 = 🍎,🍎,🍎,🍎,🍎
}Hmun khatah column indawt danin lo rem leh ta ila:
1 2 3 4 5 6 7
🔪 🍎 🍎 🍎 🍎 🍎 🔪 - 5th Row -ah thung chuan row 2 leh row 3 ang chiah khan condition kan siam ang a. a row kha 5th row a ni tih hre tel bawk ila: if( (row==5 && column==2) || (column == 6 && row==5)){
//column 2 = 🍎
//column 6 = 🍎
}else{
//column 1, 3, 4, 5, 7 = 🔪,🔪,🔪,🔪,🔪
}Hmun khatah column indawt danin lo rem leh ta ila:
1 2 3 4 5 6 7
🔪 🍎 🔪 🔪 🔪 🍎 🔪 - 6th Row-ah pawh a chunga mi ang tho hian condition kan siam ang, a row kha 6-ah kan dah thung ang. if( (row==6 && column==2) || (column == 6 && row==6)){
//column 2 = 🍎
//column 6 = 🍎
}else{
//column 1, 3, 4, 5, 7 = 🔪,🔪,🔪,🔪,🔪
}Hmun khatah column indawt danin lo rem leh ta ila:
1 2 3 4 5 6 7
🔪 🍎 🔪 🔪 🔪 🍎 🔪 - 7th Row-ah pawh a chung chiah mi ang hian condition kan siam leh dawn a ni. Row kha 7 kan tluk tir thung ang. if( (row==7 && column==2) || (column == 6 && row==7)){
//column 2 = 🍎
//column 6 = 🍎
}else{
//column 1, 3, 4, 5, 7 = 🔪,🔪,🔪,🔪,🔪
}Hmun khatah column indawt danin lo rem leh ta ila:
1 2 3 4 5 6 7
🔪 🍎 🔪 🔪 🔪 🍎 🔪
- Row hmasa ber Column 1 leh 2-ah chuan chemte kan print duh a.
- Row hmasa ber Colum 3, 4 leh 5-ah apple kan print duh a.
- Row hmasa ber Column 6 leh 7-ah chemte kan print duh a ni.
- Row 2 leh 3 ah chuan column 2 leh 6-ah apple print kan duh thung a ni.
If condition-in lo dah dawn ta ila.
row 1 = if( row ==1 && (column>2 && column<6)){ }
row 2 = if( row!=1 && ( column==2 || column==6)){ }
row 3 = if( row!=1 && ( column==2 || column==6)){ }Hmun khata kan dah chuan:if ( ((column == 2 || column ==6) && row!= 1)|| ((row == 1)&& (column>2 && column < 6))){
// Apple print tura row1-3 inkar kan column condition
// kan fullfil loh apiang hian chemte kan print dawn a ni
}
row 2 leh 3-a condition hi belchiang ta ila row!=1 kan tih hian row 1 ni lo hrim hrim kan sawina a ni ber a.Row 4 ah hian Column 2- column 6 thleng apple kan print duh avangin kan condition ah hian row == 4 kan dahtel a ngai a, a bak chu kan condition ngai kha kan la ring zel thei dawn a ni.if ( ((column == 2 || column ==6) && row!= 1)
|| ((row == 1|| row == 4)&& (column>2 && column < 6)) ){
//apple printna
}
let str = "\n";
for(let row = 1; row <= 7; row +=1 ){
for (let column = 1; column <= 7; column +=1 ){
if ( ((column == 2 || column ==6) && row!= 1)
|| ((row == 1|| row == 4)&& (column>2 && column < 6)) ){
str += '🍏';//Apple
} else {
str += "🔪";//Chemte
}
}
str += "\n";
str += "\n";
}
str +="\n";
console.log(str);
No comments :
Post a Comment