Performance Tip
- Ahmed Ramy

- Oct 2, 2017
- 1 min read

When iterating through an array Don't set the condition to be less than array.length since that loads up the pressure on the program To avoid this, set a var equal to the array size Then make the condition in the for loop less than this var To explain it Imagine u have eggs in the fridge and u need a number of eggs for a dish or something U need to keep track of the number of eggs u have So u got two choices 1- u go every time to the fridge and count the number of eggs u have which is a useless extra work 2- u bring a note، write down the number of eggs u have and done u can always return to that note u took as a reference U saved urself the trouble of going to the fridge and counting the eggs u have Same thing with the for loop condition What u r doing is making the pc ask itself on each iteration to get the size of the array and compare if its greater than the counter index Which as a results causes an unnecessary performance loss
![Project: Tic Tac Toe Game [Completed]](https://static.wixstatic.com/media/f8a557_0476422d548f489face0604bf4247a96~mv2.png/v1/fill/w_428,h_240,fp_0.50_0.50,lg_1,q_35,blur_30,enc_avif,quality_auto/f8a557_0476422d548f489face0604bf4247a96~mv2.webp)
![Project: Tic Tac Toe Game [Completed]](https://static.wixstatic.com/media/f8a557_0476422d548f489face0604bf4247a96~mv2.png/v1/fill/w_220,h_123,fp_0.50_0.50,q_95,enc_avif,quality_auto/f8a557_0476422d548f489face0604bf4247a96~mv2.webp)
![Project : Tower Of Hanoi [Completed]](https://static.wixstatic.com/media/f8a557_0841f75997644008a81f3b8c37d16207~mv2.png/v1/fill/w_447,h_250,fp_0.50_0.50,q_35,blur_30,enc_avif,quality_auto/f8a557_0841f75997644008a81f3b8c37d16207~mv2.webp)
![Project : Tower Of Hanoi [Completed]](https://static.wixstatic.com/media/f8a557_0841f75997644008a81f3b8c37d16207~mv2.png/v1/fill/w_220,h_123,fp_0.50_0.50,q_95,enc_avif,quality_auto/f8a557_0841f75997644008a81f3b8c37d16207~mv2.webp)










![Project: Tic Tac Toe Game [Completed]](https://static.wixstatic.com/media/f8a557_0476422d548f489face0604bf4247a96~mv2.png/v1/fill/w_167,h_250,fp_0.50_0.50,q_35,blur_30,enc_avif,quality_auto/f8a557_0476422d548f489face0604bf4247a96~mv2.webp)
![Project: Tic Tac Toe Game [Completed]](https://static.wixstatic.com/media/f8a557_0476422d548f489face0604bf4247a96~mv2.png/v1/fill/w_38,h_57,fp_0.50_0.50,q_95,enc_avif,quality_auto/f8a557_0476422d548f489face0604bf4247a96~mv2.webp)


![Project : Tower Of Hanoi [Completed]](https://static.wixstatic.com/media/f8a557_0841f75997644008a81f3b8c37d16207~mv2.png/v1/fill/w_328,h_250,fp_0.50_0.50,q_35,blur_30,enc_avif,quality_auto/f8a557_0841f75997644008a81f3b8c37d16207~mv2.webp)
![Project : Tower Of Hanoi [Completed]](https://static.wixstatic.com/media/f8a557_0841f75997644008a81f3b8c37d16207~mv2.png/v1/fill/w_38,h_29,fp_0.50_0.50,q_95,enc_avif,quality_auto/f8a557_0841f75997644008a81f3b8c37d16207~mv2.webp)















Comments