Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

while vs do while javascript

// while vs do...while loops

/* while loops: check condition first. If true, execute code. */
let i = 0; 
while (i < 5) {
  console.log(i); // 0 1 2 3 4
   i += 1;
}

/* do-while loops: execute code at least once even if condition is false. 
Then check condition. If true, continue executing code. */
let j = 6;
do {
  console.log(j); // 6
    j += 1;
} while (j < 5);
Comment

difference between for loop and while loop javascript

let i = 0;
//while checking for a state
while (i < 20){
  console.log(`do something while ${i} is less than 20`)
i++;
}
console.log("End of While Loop")
//for iterating a certain number of times
for(j = 0; j < 20; j++){
  console.log(`do something for ${j + 1} time(s)`)
}
console.log("End of For loop")
Comment

PREVIOUS NEXT
Code Example
Javascript :: scss in react app 
Javascript :: can i select multiple classes and give function to them at once but different in js 
Javascript :: remove cookie 
Javascript :: return jsx in for loop 
Javascript :: How to submit form with enter press in html textarea 
Javascript :: how to connect socket in react js 
Javascript :: react update version 
Javascript :: autocomplete data selected validation jquery 
Javascript :: react axios Card List 
Javascript :: como colocar dados no firebase 
Javascript :: option component in react js errors 
Javascript :: itsycal homebrew 
Javascript :: how to check if a user sent a message in discord js 
Javascript :: delay / sleep program in js 
Javascript :: js email validation 
Javascript :: jqerrt get all img alt from string 
Javascript :: get the key of largest json array value 
Javascript :: html js display pdf file 
Javascript :: Delete a Cookie with JavaScript 
Javascript :: Function.prototype.bind polyfill 
Javascript :: vue date helper 
Javascript :: string to number javascript 
Javascript :: array prototype find javascript 
Javascript :: extend current date with 30 days in jquery datepicker 
Javascript :: copying table element to clipboard using javascript 
Javascript :: rotate13 text in javascript 
Javascript :: dart how to convert json to x-www-form-urlencoded 
Javascript :: sort array of objects based on another array javascript 
Javascript :: Reactjs exemple class component 
Javascript :: vue not loading env variables 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =