Control Flow in JavaScript

Control Flow in JavaScript

Updating
  • Reads
  • Likes
  • Chapters
Category: Non-Fiction
Control flow in JavaScript is a fundamental concept that dictates the order in which statements are executed within a script. It enables developers to control the flow of program execution based on conditions and loops. Understanding control flow is essential for writing efficient and logic-driven JavaScript code.

Conditional Statements

Conditional statements allow developers to execute code based on specific conditions. JavaScript provides several types of conditional statements:

if statement: This statement evaluates a condition and executes a block of code if the condition is true. For example:

if (condition) {
// Code block to execute if condition is true
}

if...else statement: It executes one block of code if a condition is true and another block if the condition is false. Example:

if (condition) {
// Code block to execute if condition is true
} else {
// Code block to execute if condition is false
}

else if statement: This statement allows for multiple conditions to be checked sequentially. Example:

if (condition1) {
// Code block to execute if condition1 is true
} else if (condition2) {
// Code block to execute if condition2 is true
} else {
// Code block to execute if neither condition1 nor condition2 is true
}
switch statement: It evaluates an expression and executes code based on a matching case label. Example:

switch (expression) {
case value1:
// Code block to execute if expression equals value1
break;
case value2:
// Code block to execute if expression equals value2
break;
default:
// Code block to execute if expression doesn't match any case
}

Loops

Loops are used to execute a block of code repeatedly until a specified condition is met. JavaScript supports different types of loops:

for loop: Executes a block of code a specified number of times. Example:

for (initialization; condition; iteration) {
// Code block to execute

Chapter list

- Last updated at 06:15 03-05-2024

Related stories

Bloody Vows | Eric Coulter x OFC

Over 200 years ago, vampires crawled from the shadows to conquer the human race, which led to the collapse of modern society. In Chicago, the bloodthirsty creatures divided themselves into five factions, and the humans, upon reaching 20 years of age, had to partake in the Choosing Ceremony that decided which faction they would pledge their loyalty to. Blood in exchange for protection against other dangers hidden in the darkness.Kate Kempton is a human on a mission. Her older sister's mysterious death led to a dangerous resolve. Upon coming of age, she would join Dauntless to find out what really happened three years before. Unfortunately, on Choosing Day, Kate draws the attention of Eric Coulter, the cruel and young faction leader, who had never been intrigued by a human before.Can she survive the warrior faction and find answers? What will get her killed first, Eric or the secrets buried deep into the faction?---Divergent characters belong to Veronica Roth. I only own my original characters.Available on AO3. Don't copy or translate to other platforms.This story is loosely based on the movies. I use the Divergent world as a foundation for a mostly non-canon story.
The Head Alpha's Widow Beta

Alexander turned 20 and on his 20th birthday, he found that his now father's beta is his mate. He was beyond happy because he always had a tiny little crush on the beta and hoped that the beta was his mate, he didn't mind the age gap.Michael is 30 years old and have been the beta of the head alpha of the black moon pack since he was 18, he was going to continue to be the beta for the head alpha's son but the tables turned when the head alpha's son was his fated mate.What will happen when Alexander comes to know that his mate was mated to someone before, but now is a widow.
Trapped

When Alexandra-Alex-Ryan was ten, both of her parents were murdered in front of her eyes, and the killers were never brought to justice. The memory of that incident haunted her all her life, but that didn't stop her from joining the FBI, following in her father's footsteps. She got partnered with Liam Hunt, an arrogant special agent. While working together, they found themselves in front of a murder case that might uncover the mystery behind what happened to Alex's parents. They encountered a lot of obstacles while trying to disclose the secrets and bring the truth to light, and they found out that it was far more complicated and dangerous than they ever imagined.Alex has been trapped in the past since that fateful day. So what will happen when the pages of the past get reopened?
Boating Buddies (Yandere Spongebob x Squidward)

SpongeBob SquarePants is known for his joyous personality and laughter. Most of the folks of Bikini Bottom love the guy, especially his handywork with a krabby patty. But Squidward Tentacles never believed it. As of late, there has been something drastically wrong with his co-worker. Will SpongeBob's true intentions be revealed? It's easy to forget that there is much more hidden beneath the holes of a sea sponge.A yandere spongebob x squidward (tw all applicable) uwu#1 in taxidermy#4 in plankton#8 in mrkrabs #5 in squidwardtentacles#45 in spongebob#3 in clarinet #29 in squidward
Gravity Falls AUs

Gravity Falls Alternate Universes! Most of them will be listed here! Recommend AUs in the comments! There are underrated and popular AUs alike here!
MCU reacts to Warhammer 40K

The Avengers, Asgardians and The Guardians react to the Grim Darkness of Warhammer 40K.Pietro Maximoff lives, Frigga Lives, Bruce Banner doesn't go to Sakaar.
Lord Of The Mysteries (chp.1-200)

Author :Cuttlefish that loves diving爱潜水的乌贼This is for offline reading purposes only this is not my work Everything belongs to It's rightful owner, cuttlefish
Generations | الاجَيال

... ؛ جيِّلَ الوحَشَ المُنفردْ حِيثُ الرؤوسَ تتَسابقُ لأحتِضانَ الأرضَ." Ran away and you will see death " ;D | 1890 ^

You may also like

2012!TMNT & ROTTMNT AU Story Prompts

Exactly what the title says. I'll be posting AU story ideas based of the 2012 and Rise incarnations of the popular TMNT franchise! You're allowed to use them as inspiration for your own stories, just give me credit if you do use them and include the required lines!That should be it! Enjoy!

356 6 10 Full
Bloody Vows | Eric Coulter x OFC

Over 200 years ago, vampires crawled from the shadows to conquer the human race, which led to the collapse of modern society. In Chicago, the bloodthirsty creatures divided themselves into five factions, and the humans, upon reaching 20 years of age, had to partake in the Choosing Ceremony that decided which faction they would pledge their loyalty to. Blood in exchange for protection against other dangers hidden in the darkness.Kate Kempton is a human on a mission. Her older sister's mysterious death led to a dangerous resolve. Upon coming of age, she would join Dauntless to find out what really happened three years before. Unfortunately, on Choosing Day, Kate draws the attention of Eric Coulter, the cruel and young faction leader, who had never been intrigued by a human before.Can she survive the warrior faction and find answers? What will get her killed first, Eric or the secrets buried deep into the faction?---Divergent characters belong to Veronica Roth. I only own my original characters.Available on AO3. Don't copy or translate to other platforms.This story is loosely based on the movies. I use the Divergent world as a foundation for a mostly non-canon story.

25 5 5
Basically Ship Rating🙂

Helloo :3I'm just gonna rate ships here from various fandoms (obviously which I know)It's just my opinion and you can present your own opinion if you wantThank you :D

180 5 12
The Knights and the Princess

She wasn't quite sure what to make of her situation. Suddenly appearing in a time that was oddly reminiscent of different time, what was she supposed to believe or do? With talks of mystical "curses" and dragons, and war and death every time you turn a corner, it could almost be considered a nightmare.

874.9K 40 26.9K Full
The Chronicle of Aurelia Aurelius

Can I twist my own fate? Can I avoid my own death? Even the Goddess is trying to make my death come true with her paragon...I will do the opposite of the book of my own fate, and not give any care about the events of the book, what will go wrong about that? What will go wrong with doing what you want to be?But...in the book, I am being called as "Villainess.".

25.6K 55 550
Forbidden Love || Anakin x Reader

Y/n Amidala was only known as Padme's little sister until she met Anakin Skywalker. Her whole life was changed upside as she found herself in love with Jedi. This isn't a regular love story, no. Y/n Amidala had so much power in the force; she became one herself. Their love was forbidden amongst the Jedi Order. Throughout the story, both lovers go through the most challenging levels of their love. Defeated by the dark side one will go through, but who? ✧・゚: *✧・゚:*    *:・゚✧*:・゚✧"Have faith my love." Anakin says. he placed his hand on my cheek and caressed it. Panic filled the city, in the far distance was the temple burning into flames. I sensed fear and hatred in him. I trusted him. I knew him. I know what his intentions are.. or so I thought.----DISCLAIMER: I do not own of any Lucas Film Disney or anything related to Star Wars. I do now own any of the iconic characters except for my own characters that I have created. ---

597.4K 127 15.9K
DIA YANG TERBAIK UNTUKKU  | OG

Karya kedua. Pada mulanya hidup Khayla Nafeesa penuh dengan warna warni. Suasana hidupnya yang ceria dapat menjadikan hari-harinya indah.Satu perkara. Ya, perkara yang mengubah keseluruhan hidup Khayla Nafeesa. Qays Luqman seorang lelaki yang penuh dengan sifat baran di dalam dirinya. Marah hanyalah satu cara Qays melampiaskan kepada Khayla. "Kau ingat kahwin dengan aku, kau boleh senang? You are wrong Khayla. Aku akan pastikan hidup kau hancur binasa." - Qays Luqman "Hargai saya selayaknya Qays. Sekurangnya hanya atas dasar berperikemanusiaan." - Khayla Nafeesa "No perempuan gila. Kau hancurkan impian aku. Aku takkan layan kau dengan baik. Takkan." - Qays Luqman "Forever you will be mine Qays Luqman." - Dahlia Zalikha Pukul, sepak, diterajang, tumbuk, dilempar sesuatu apa lagi yang Khayla tidak pernah rasakan. Semuanya dia pernah hadap. Dia hanya mahukan rasa dihargai dan disayangi oleh Qays Luqman, tetapi dia tahu perempuan sepertinya tidak layak disayangi. "Mungkin ini adalah cara awak sayangkan saya, saya terima." - Khayla Nafeesa"Dasar perempuan murahan, kau ingat aku akan termakan dengan kata-kata kau?!" - Qays LuqmanPada akhirnya, Khayla hanya berserah. Mampukah Khayla menemukan cahaya kebahagiaan dia bersama Qays Luqman ataupun tidak?Start : 13 Nov 2023

6.8K 23 192
using the tools at hand

Embittered former lovers, difficult choices, a sword, a gun and some fun.All rights reserved.

3 1 0 Full
Demigods react to Percy's Ships

This is about the seven and some others reacting to all the people Percy is shipped to

12.8K 14 123 Full
The game of twisted fates {ON HIATUS}

A Danganronpa x Kny crossoverCredit to @akanebitch69 for giving me the idea for making this :)(More details will be explained before starting the story)In a regular world with regular life's, Zenitsu is a normal student in kimetsu Academy. But when his beloved gramps gets a terminal illness and can't sustain himself and his brother, he's given a to win a million of a summer break event which sounds convincing at first then later turns to a cruel game of survival to the death, where only one comes victorious or they find a alternative way of escaping. Can he even escape alive with the others trapped with him or fall into insanity trying?

486 16 0