Iterations

Wa maxey Iterations ? Iterations wa loop ama wareeg, waxaana uu naga caawiya inaan so saarno macluumaad tiro badan, si nadaamsan walibo la fahmi karo.

Types of loops || Noocyada loops ka

Waxaa jiro sedex nooc oo loop ah waxa eyna kala yihin:

 

Dhamaantod isku shaqo ayey qabtaan waxa kaliya eyku kala duwan yihin wa sida ey shaqada u qabanayan. Sidokale waxaad loop ku sameen kartaa Arrays.

 

Advantage of loops || Faaidada loops

Waxaad record gareysay ama aad keydisey macluumaad, kadib waxaad rabtaa inaad so bandhigto macluumaadkas, Loops waxa ey ku fududeneysa inaad so daabacdo macluumaadkas tirada badan adigo qorayo less code yacni lines code ah oona badneen.

 

For loops syntax || hab qoraalka For loops
				
					for (initializer; condition; action) {
  //some data...
}
				
			

initializer wa inaad u sheegta loop ka mesha uu shaqada ka bilaabayo, condition wa mesha checking ka hubinta eyka dhaceyso, action inta conditon uu true/haa yahay ficilka lasameenayo.

For loops example
				
					const people = ["ahmed", "adam", "asad"];

for (let person = 0; person < 3; person++) {
  console.log(people[person]);
}
				
			

Tusaalahan kore waxa uu so saari doona magacyada: ahmed, adam, asad.

Hadii loops eysan jiri laheen, oo aad rabto inaad so saarto xogtaan kor ku xusan okale waxaad ku qasbanaan laheed inaan qorto lines tiro badan.

Example || Tusaale 
				
					const people = ["ahmed", "adam", "asad"];

console.log(people[0]); // ahmed
console.log(people[1]); // adam
console.log(people[2]); // asad
				
			
 
While loops syntax || hab qoraalka While loops
				
					let z = 0; // initiazer
while (condtion) {
  z++; // action
}
				
			

 

While loops example
				
					const people = ["ahmed", "adam", "asad"];

let x = 0;
while (x < people.length) {
  console.log(people[x]);
  x++;
}
				
			

 

Conclusion

Aqriste waxaan rajeenaya inaad wax badan ka fahantey qormaadan.

Next Lesson >

Share