Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Basics: The for loop

Friday, November 19, 2021

JavaScript Basics: The for loop

The for loop is a looping construct in JavaScript that are more simplistic than the while loop.   When writing the for loop there are three three parts they are


  1.  Initialize - a count variable is initialize, it's usually zero but it doesn't have to be
  2. Test - A test to see if the loop should continue
  3. Increment - finally the count is incremented, it doesn't have to be an increment it could be decrements as well

Let's use the JavaScript code to demonstrate:

If you execute the loop below you will bet a for loop that executes when i is less than 10


for (var i = 0; i < 10; i++)
{
    console.log("i is " + i);
}

console.log("i outside of for look is " + i);


Here is the output:
























Noticed the number outside of the loop is bigger than the number that's inside the loop on the last execution.  Just keep that in mind when you are working with a for loop.  If you want to execute on the tenth loop you have to change your test condition to say i <= 10.  This implies that i has to be less than or equal to 10 before the loop stops executing

Here is the output:




















Although the value outside of the loop is now 11!



2 comments:

  1. Sobat CUAN, setuju gak sih kalau untuk menjalankan aktivitas sehari-hari sebagai online seller dengan lancar, kamu membutuhkan perangkat atau aplikasi pendukung yang bisa mempermudah pekerjaanmu?
    Dengan adanya aplikasi pendukung, tentunya kamu akan lebih bisa menerapkan sosial media dan digital marketing dengan lebih tepat sasaran. Berikut ini adalah 4 aplikasi pendukung aktivitas bisnis online yang sedang kamu jalankan.
    Sobat CUAN sudah installed yang mana? Share di kolom komentar ya!
    #hidupcuan #milenialkayadanmandiri #olshopindonesia #olshopindo #reseller #olshopjakarta #marketplace #tokopedia #mulaidarisekarang #mulaidarisini #jualanonlineshop #suksesjualanonline #socialmediamarketing #digitalmarketing
    to know more:https://hidupcuan.com/

    ReplyDelete
    Replies





    1. error404-store




      - -- Spamming tools --




      1-- cpanel https ssl secure
      2-- shell ssl secure
      3-- web-mail
      4-- smtp
      5-- rdp with send bluster
      6-- scam pages
      7-- ceo or cfo leads




      -- Spy virus slinet Exploits --




      1-- privet rat
      2-- crypter exploits
      3-- privet rdp hosting
      4-- os andriod spy virus
      5-- iso iPhone spy virus
      6-- Nokia spy virus




      - -- scanners brute-force ---




      1-- linux roots
      2-- cpanel scanner
      3-- cpanel bruter
      4-- shell scanner
      5-- smtp scanner
      6-- smtp bruter
      7-- zimbra scanners


      - -------------------


      cpanel,shell,smtp,scampages,sender,ceo or cfo leads,rdp,spyvirus,crypter,exploits,scanners


      Telegram:- @Donsmith000


      icq :- @Donsmith000


      https://error404-store.blogspot.com



      Delete

Search This Blog