SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Intro to Loops
Continued
Diving Deeper into JavaScript Control Statements
(Loops)
- Professor Flo Davis… Mwahaha
Increment/
Decrement Operators
i++ is the same as i = i + 1;
i- - is the same as i = i -1;
Increment Operator
Syntax x++ or ++x
//PostFix
var x = 3;
y = x++ // y =3, x=4
//PreFix
var a = 2;
b = ++a; // a = 3, b =3
Working Example https://developer.mozilla.org/en-US/docs/
Web/JavaScript/Reference/Operators/Arithmetic_Operators
Increment Operator
Example
var x = 5;
x++;
var z = x;
console.log(z) // z = 6;
Working Example http://www.w3schools.com/
js/tryit.asp?filename=tryjs_oper_increment
Decrement Operator
The decrement operator subtracts
Syntax x - - or - - x
// Postfix
var x = 3;
y = x - - ; y = 3, x = 2
// Prefix
var a = 2;
b = - - a; // a = 1, b = 1
Working Example https://developer.mozilla.org/en-US/docs/Web/
JavaScript/Reference/Operators/Arithmetic_Operators
Decrement Operator
Example
var x = 5;
x- - ;
var z = x; // z = 4
Working Example http://
www.w3schools.com/js/tryit.asp?
filename=tryjs_oper_decrement
The For Loop
for(initialize; test; increment/
decrement) { // Code Block//}
Example Standard For Loop
for(var i = 0; i<10; i++)
{console.log(i);} // This will print the
numbers from 1 through 10.
We use i, because that is short for index
For Loop Example
(Decrement)
for(var i=10; i>5; i- - )
{ console.log(i);}
REMEMBER: i++ or i - - is the same
as i+=1, or i -=1, code what ever
works for you best.
Looping Through An
Array with For Loop
var Professor = [‘Florence’, ‘Davis’];
for(var i =0; i<Professor.length;i++)
{console.log(Professor[i]);}
// Let’s refactor code and make it cleaner
var Professor = [‘Florence’, ‘Davis’];
var length = Professor.length;
for(var i = 0; i<length;i++)
{console.log(Professor[i]);}
Oh…It’s Been Awhile
While Loops
While Loops
while(condition) {// statement}
Example var i = 0;
while(i<10){ console.log(i + ‘….. this will go on until we hit
10’);
i += 1; // same as i++ throwing you for a loop making sure
your paying attention haha :) , remember they can be used
interchangeably whatever you prefer.
If you need further explanations don’t forget our good
friends at Mozilla: https://developer.mozilla.org/en-US/
docs/Web/JavaScript/Reference/Statements/while
While Loops II
var n = 0;
while(n < 3) { console.log(“Looping,”);
n++;}
// Will print looping 3 times
Looping…
looping…
Looping…
–Johnny Appleseed
“Happy Coding.”

Mais conteúdo relacionado

Mais procurados

Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
Karwan Mustafa Kareem
 
Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
Jd Mercado
 

Mais procurados (20)

Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Looping
LoopingLooping
Looping
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loops in c
Loops in cLoops in c
Loops in c
 
Nested loops
Nested loopsNested loops
Nested loops
 
Loop c++
Loop c++Loop c++
Loop c++
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
Looping statement
Looping statementLooping statement
Looping statement
 
Loop control in c++
Loop control in c++Loop control in c++
Loop control in c++
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
Iteration Statement in C++
Iteration Statement in C++Iteration Statement in C++
Iteration Statement in C++
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
 
Control statements
Control statementsControl statements
Control statements
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Loops c++
Loops c++Loops c++
Loops c++
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
 
Looping statements
Looping statementsLooping statements
Looping statements
 

Destaque (10)

JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScript
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Event loops in java script 01 - stack
Event loops in java script 01 - stackEvent loops in java script 01 - stack
Event loops in java script 01 - stack
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and Variables
 
The Loops
The LoopsThe Loops
The Loops
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Javascript Function
Javascript FunctionJavascript Function
Javascript Function
 

Semelhante a Loops in JavaScript

Web app development_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05
Hassen Poreya
 

Semelhante a Loops in JavaScript (20)

M C6java6
M C6java6M C6java6
M C6java6
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
JavaFXScript
JavaFXScriptJavaFXScript
JavaFXScript
 
Web app development_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05
 
Java tut1
Java tut1Java tut1
Java tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Php + my sql
Php + my sqlPhp + my sql
Php + my sql
 
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eEo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5e
 
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eEo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5e
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Python - Lecture 2
Python - Lecture 2Python - Lecture 2
Python - Lecture 2
 
control statements
control statementscontrol statements
control statements
 
Python programing
Python programingPython programing
Python programing
 
Elixir/OTP for PHP developers
Elixir/OTP for PHP developersElixir/OTP for PHP developers
Elixir/OTP for PHP developers
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Looping
LoopingLooping
Looping
 

Último

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 

Último (20)

Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

Loops in JavaScript

  • 1. Intro to Loops Continued Diving Deeper into JavaScript Control Statements (Loops) - Professor Flo Davis… Mwahaha
  • 2. Increment/ Decrement Operators i++ is the same as i = i + 1; i- - is the same as i = i -1;
  • 3. Increment Operator Syntax x++ or ++x //PostFix var x = 3; y = x++ // y =3, x=4 //PreFix var a = 2; b = ++a; // a = 3, b =3 Working Example https://developer.mozilla.org/en-US/docs/ Web/JavaScript/Reference/Operators/Arithmetic_Operators
  • 4. Increment Operator Example var x = 5; x++; var z = x; console.log(z) // z = 6; Working Example http://www.w3schools.com/ js/tryit.asp?filename=tryjs_oper_increment
  • 5. Decrement Operator The decrement operator subtracts Syntax x - - or - - x // Postfix var x = 3; y = x - - ; y = 3, x = 2 // Prefix var a = 2; b = - - a; // a = 1, b = 1 Working Example https://developer.mozilla.org/en-US/docs/Web/ JavaScript/Reference/Operators/Arithmetic_Operators
  • 6. Decrement Operator Example var x = 5; x- - ; var z = x; // z = 4 Working Example http:// www.w3schools.com/js/tryit.asp? filename=tryjs_oper_decrement
  • 7. The For Loop for(initialize; test; increment/ decrement) { // Code Block//} Example Standard For Loop for(var i = 0; i<10; i++) {console.log(i);} // This will print the numbers from 1 through 10. We use i, because that is short for index
  • 8. For Loop Example (Decrement) for(var i=10; i>5; i- - ) { console.log(i);} REMEMBER: i++ or i - - is the same as i+=1, or i -=1, code what ever works for you best.
  • 9. Looping Through An Array with For Loop var Professor = [‘Florence’, ‘Davis’]; for(var i =0; i<Professor.length;i++) {console.log(Professor[i]);} // Let’s refactor code and make it cleaner var Professor = [‘Florence’, ‘Davis’]; var length = Professor.length; for(var i = 0; i<length;i++) {console.log(Professor[i]);}
  • 11. While Loops while(condition) {// statement} Example var i = 0; while(i<10){ console.log(i + ‘….. this will go on until we hit 10’); i += 1; // same as i++ throwing you for a loop making sure your paying attention haha :) , remember they can be used interchangeably whatever you prefer. If you need further explanations don’t forget our good friends at Mozilla: https://developer.mozilla.org/en-US/ docs/Web/JavaScript/Reference/Statements/while
  • 12. While Loops II var n = 0; while(n < 3) { console.log(“Looping,”); n++;} // Will print looping 3 times Looping… looping… Looping…