ﻪﻘﻠﺣ ﯼﺍﺮﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


فهرست مطالب

    نمایش فهرست مطالب


.ﺪﻨﻨﮐ ﺍﺮﺟﺍ ﺭﺎﺑ ﻦﯾﺪﻨﭼ ﺍﺭ ﺪﮐ ﮎﻮﻠﺑ ﮏﯾ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﺎﻫ ﻪﻘﻠﺣ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﻪﻘﻠﺣ

ﻡﺍﺪﮐ ﺮﻫ ،ﺪﯿﻨﮐ ﺍﺮﺟﺍ ﺎﻫﺭﺎﺑ ﻭ ﺎﻫﺭﺎﺑ ﺍﺭ ﺪﮐ ﻥﺎﻤﻫ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺮﮔﺍ ،ﺪﻨﺘﺴﻫ ﺪﯿﻔﻣ ﺎﻫ ﻪﻘﻠﺣ

:ﺪﻫﺩ ﯽﻣ ﺥﺭ ﺎﻫ ﻪﯾﺍﺭﺁ ﺎﺑ ﺭﺎﮐ ﻡﺎﮕﻨﻫ ﺭﺩ ﺩﺭﻮﻣ ﻦﯾﺍ ﺐﻠﻏﺍ

:ﻦﺘﺷﻮﻧ ﯼﺎﺟ ﻪﺑ

 text += cars[0] + "<br>"; 
text += cars[1] + "<br>"; 
 text += cars[2] + "<br>"; 
text += cars[3] + "<br>"; 
 text += cars[4] + "<br>"; 
text += cars[5] + "<br>";

:ﺪﯿﺴﯾﻮﻨﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

for (let i = 0; i < cars.length; i++) { 
  text += cars[i] + "<br>";
 }

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript For Loop</h2>

<p id="demo"></p>

<script>
const cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"];

let text = "";
for (let i = 0; i < cars.length; i++) {
  text += cars[i] + "<br>";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

ﺎﻫ ﻪﻘﻠﺣ ﻒﻠﺘﺨﻣ ﻉﺍﻮﻧﺍ

:ﺪﻨﮐ ﯽﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺍﺭ ﺎﻫ ﻪﻘﻠﺣ ﺯﺍ ﯽﻔﻠﺘﺨﻣ ﻉﺍﻮﻧﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ

  • ﯼﺍﺮﺑ - ﺩﻮﺷ ﯽﻣ ﻪﻘﻠﺣ ﺪﮐ ﮎﻮﻠﺑ ﮏﯾ ﻖﯾﺮﻃ ﺯﺍ ﺭﺎﺑ ﻦﯾﺪﻨﭼ

  • for/in - ﺪﻧﺯ ﯽﻣ ﻪﻘﻠﺣ ءﯽﺷ ﮏﯾ ﺕﺎﯿﺻﻮﺼﺧ ﻖﯾﺮﻃ ﺯﺍ

  • for/of - ﺪﻨﮐ ﯽﻣ ﺭﻮﺒﻋ ﻪﻘﻠﺣ ﮏﯾ ﺮﯾﺩﺎﻘﻣ ﻥﺎﯿﻣ ﺯﺍ

  • ﻪﮐ ﯽﻟﺎﺣ ﺭﺩ - ﺖﺳﺍ ﺖﺳﺭﺩ ﻩﺪﺷ ﺺﺨﺸﻣ ﻁﺮﺷ ﮏﯾ ﻪﮐ ﯽﻟﺎﺣ ﺭﺩ ﺪﻧﺯ

  • do/while - ﺩﻮﺷ ﯽﻣ ﻪﻘﻠﺣ ﺪﮐ ﮎﻮﻠﺑ ﮏﯾ ﻖﯾﺮﻃ ﺯﺍ ،ﺖﺳﺍ ﺖﺳﺭﺩ


for ﻪﻘﻠﺣ

:ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﯼﺭﺎﯿﺘﺧﺍ ﺕﺭﺎﺒﻋ 3 ﺎﺑ ﻪﻘﻠﺣ ﮏﯾ for ﺭﻮﺘﺳﺩ

for (expression 1; expression 2; expression 3) {
      // code block to be executed
 }

1 ﺕﺭﺎﺒﻋ ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ (ﺭﺎﺑ ﮏﯾ) ﺪﮐ ﮎﻮﻠﺑ ﯼﺍﺮﺟﺍ ﺯﺍ ﻞﺒﻗ.

2 ﺕﺭﺎﺒﻋ ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﺪﮐ ﮎﻮﻠﺑ ﯼﺍﺮﺟﺍ ﻂﯾﺍﺮﺷ.

3 ﺕﺭﺎﺒﻋ (ﺭﺎﺑ ﺮﻫ) ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﺪﮐ ﮎﻮﻠﺑ ﯼﺍﺮﺟﺍ ﺯﺍ ﺲﭘ.

ﻝﺎﺜﻣ

for (let i = 0; i < 5; i++) {
   text += "The number is " + i + "<br>";
}
 

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript For Loop</h2>

<p id="demo"></p>

<script>
let text = "";

for (let i = 0; i < 5; i++) {
  text += "The number is " + i + "<br>";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

:ﺪﯿﻧﺍﻮﺨﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻻﺎﺑ ﻝﺎﺜﻣ ﺯﺍ

.(i=0 ﺪﯾﺭﺍﺬﮕﺑ) ﺪﻨﮐ ﯽﻣ ﻢﯿﻈﻨﺗ ﻪﻘﻠﺣ ﻉﻭﺮﺷ ﺯﺍ ﻞﺒﻗ ﺍﺭ ﺮﯿﻐﺘﻣ ﮏﯾ 1 ﺕﺭﺎﺒﻋ

ﺯﺍ ﺮﺘﻤﮐ ﺪﯾﺎﺑ i) ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﻪﻘﻠﺣ ﯼﺍﺮﺟﺍ ﯼﺍﺮﺑ ﺍﺭ ﯽﻄﯾﺍﺮﺷ 2 ﺕﺭﺎﺒﻋ

ﺪﻫﺩ ﯽﻣ ﺶﯾﺍﺰﻓﺍ ﺍﺭ (++i) ﺭﺍﺪﻘﻣ ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﻘﻠﺣ ﺭﺩ ﺪﮐ ﮎﻮﻠﺑ ﻪﮐ ﺭﺎﺑ ﺮﻫ 3 ﺕﺭﺎﺒﻋ



1 ﻥﺎﯿﺑ

.(i=0 ﺪﯾﺭﺍﺬﮕﺑ) ﺪﯿﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﻘﻠﺣ ﺭﺩ ﻩﺩﺎﻔﺘﺳﺍ ﺩﺭﻮﻣ ﺮﯿﻐﺘﻣ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﯼﺍﺮﺑ 1 ﺕﺭﺎ

ﺖﺳﺍ 1 ﺕﺭﺎﺒﻋ .ﺪﻫﺩ ﯽﻤﻧ ﯽﺘﯿﻤﻫﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ .ﺖﺴﯿﻧ ﺭﻮﻄﻨﯾﺍ ﻪﺸﯿﻤﻫ

:ﺪﯿﻨﮐ ﻉﻭﺮﺷ (ﺪﯿﻨﮐ ﺍﺪﺟ ﻢﻫ ﺯﺍ ﺎﻣﺎﮐ ﺎﺑ) 1 ﺕﺭﺎﺒﻋ ﺭﺩ ﺍﺭ ﯼﺩﺎﯾﺯ ﺮﯾﺩﺎﻘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

for (let i = 0, len = cars.length, text = ""; i < len; i++) { 
  text += cars[i] + "<br>";
 }

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript For Loop</h2>

<p id="demo"></p>

<script>
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let i, len, text;
for (i = 0, len = cars.length, text = ""; i < len; i++) {
  text += cars[i] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

ﺪﻧﺍ ﻩﺪﺷ ﻢﯿﻈﻨﺗ ﺎﻤﺷ ﺮﯾﺩﺎﻘﻣ ﻪﮐ ﯽﻧﺎﻣﺯ ﻞﺜﻣ) ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ 1 ﺕﺭﺎﺒﻋ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﻭ

ﻝﺎﺜﻣ

let i = 2;
let len = cars.length;
let text = "";
for (; i < len; i++) { 
    text += cars[i] + "<br>";
 }

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript For Loop</h2>

<p id="demo"></p>

<script>
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let i = 2;
let len = cars.length;
let text = "";

for (; i < len; i++) {
  text += cars[i] + "<br>";
}

document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

2 ﻥﺎﯿﺑ

.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﯿﻟﻭﺍ ﺮﯿﻐﺘﻣ ﻂﯾﺍﺮﺷ ﯽﺑﺎﯾﺯﺭﺍ ﯼﺍﺮﺑ 2 ﺕﺭﺎﺒﻋ ﺯﺍ ﺐﻠﻏﺍ

ﺖﺳﺍ 2 ﺕﺭﺎﺒﻋ .ﺪﻫﺩ ﯽﻤﻧ ﯽﺘﯿﻤﻫﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ .ﺖﺴﯿﻧ ﺭﻮﻄﻨﯾﺍ ﻪﺸﯿﻤﻫ

،ﺪﻧﺍﺩﺮﮔﺮﺑ false ﺮﮔﺍ .ﺩﻮﺷ ﯽﻣ ﻉﻭﺮﺷ ﻩﺭﺎﺑﻭﺩ ﻪﻘﻠﺣ ،ﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ true ۲ ﺕﺭﺎﺒﻋ ﺮﮔﺍ

ﺪﯿﻫﺩ ﻪﺋﺍﺭﺍ ﻥﺁ ﻞﺧﺍﺩ ﺭﺩ break ﮏﯾ ﺪﯾﺎﺑ ،ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ 2 ﺕﺭﺎﺒﻋ ﺮﮔﺍ


3 ﻥﺎﯿﺑ

.ﺪﻫﺩ ﯽﻣ ﺶﯾﺍﺰﻓﺍ ﺍﺭ ﻪﯿﻟﻭﺍ ﺮﯿﻐﺘﻣ ﺭﺍﺪﻘﻣ 3 ﺕﺭﺎﺒﻋ ﺐﻠﻏﺍ

ﺖﺳﺍ 3 ﺕﺭﺎﺒﻋ .ﺪﻫﺩ ﯽﻤﻧ ﯽﺘﯿﻤﻫﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ .ﺖﺴﯿﻧ ﺭﻮﻄﻨﯾﺍ ﻪﺸﯿﻤﻫ

ﺪﻫﺩ ﻡﺎﺠﻧﺍ ﺍﺭ ﺖﺒﺜﻣ ،(--i) ﯽﻔﻨﻣ ﺶﯾﺍﺰﻓﺍ ﺪﻨﻧﺎﻣ ﯼﺭﺎﮐ ﺮﻫ ﺪﻧﺍﻮﺗ ﯽﻣ 3 ﺕﺭﺎﺒﻋ

:(ﺪﯿﻫﺩ ﯽﻣ ﺶﯾﺍﺰﻓﺍ ﻪﻘﻠﺣ ﻞﺧﺍﺩ ﺭﺩ ﺍﺭ ﺩﻮﺧ ﺮﯾﺩﺎﻘﻣ ﻪﮐ ﯽﻧﺎﻣﺯ ﺪﻨﻧﺎﻣ) ﺩﺮﮐ ﻑﺬﺣ ﻥﺍﻮﺗ ﯽﻣ ﺰﯿﻧ ﺍﺭ 3

ﻝﺎﺜﻣ

let i = 0;
let len = cars.length;
let text = "";
for (; i < len; ) { 
  text += cars[i] + "<br>";
   
 i++;
}

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript For Loop</h2>

<p id="demo"></p>

<script>
const cars = ["BMW", "Volvo", "Saab", "Ford"];

let i = 0;
let len = cars.length;
let text = "";

for (; i < len; ) {
  text += cars[i] + "<br>";
  i++;
}
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>

ﻪﻘﻠﺣ ﻩﺩﻭﺪﺤﻣ

:ﻪﻘﻠﺣ ﮏﯾ ﺭﺩ var ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

ﻝﺎﺜﻣ

var i = 5;

for (var i = 0; i < 10; i++) {
  // some code
}

// Here i is 10

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript let</h2>

<p id="demo"></p>

<script>
var i = 5;
for (var i = 0; i < 10; i++) {
  // some statements
}
document.getElementById("demo").innerHTML = i;
</script>

</body>
</html>

:ﻪﻘﻠﺣ ﮏﯾ ﺭﺩ let ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

ﻝﺎﺜﻣ

let i = 5;

for (let i = 0; i < 10; i++) {
    // some code
}

// Here i is 5

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript let</h2>

<p id="demo"></p>

<script>
let i = 5;
for (let i = 0; i < 10; i++) {
  // some statements
}
document.getElementById("demo").innerHTML = i;
</script>

</body>
</html>

ﺭﺩ ﻩﺪﺷ ﻡﻼﻋﺍ ﺮﯿﻐﺘﻣ ،var ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ،ﻝﻭﺍ ﻝﺎﺜﻣ ﺭﺩ

ﺭﺩ ﻩﺪﺷ ﻡﻼﻋﺍ ﺮﯿﻐﺘﻣ ،let ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ،ﻡﻭﺩ ﻝﺎﺜﻣ ﺭﺩ

i ،ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﻘﻠﺣ ﮏﯾ ﺭﺩ i ﺮﯿﻐﺘﻣ ﻡﻼﻋﺍ ﯼﺍﺮﺑ let


For/InFor/Of ﯼﺎﻫﻪﻘﻠﺣ

.ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﯼﺪﻌﺑ ﻞﺼﻓ ﺭﺩ for/of ﻪﻘﻠﺣ ﻭ


ﻪﮐ ﯽﻟﺎﺣ ﺭﺩ ﺩﻮﺷ ﯽﻣ ﻪﻘﻠﺣ

.ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﯼﺪﻌﺑ ﯼﺎﻫ ﻞﺼﻓ ﺭﺩ do/while