Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Looping
Search
John Nunemaker
PRO
September 24, 2009
Programming
0
6
Looping
John Nunemaker
PRO
September 24, 2009
Tweet
Share
More Decks by John Nunemaker
See All by John Nunemaker
Atom
jnunemaker
PRO
9
4.1k
MongoDB for Analytics
jnunemaker
PRO
10
800
Addicted to Stable
jnunemaker
PRO
32
2.4k
MongoDB for Analytics
jnunemaker
PRO
21
2.2k
MongoDB for Analytics
jnunemaker
PRO
16
30k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Why NoSQL?
jnunemaker
PRO
10
890
Don't Repeat Yourself, Repeat Others
jnunemaker
PRO
7
3.3k
I Have No Talent
jnunemaker
PRO
14
920
Other Decks in Programming
See All in Programming
Ethereum_.pdf
nekomatu
0
460
CSC509 Lecture 11
javiergs
PRO
0
180
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Quine, Polyglot, 良いコード
qnighy
4
640
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Jakarta EE meets AI
ivargrimstad
0
530
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Realtime API 入門
riofujimon
0
150
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
A better future with KSS
kneath
238
17k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Gamification - CAS2011
davidbonilla
80
5k
Practical Orchestrator
shlominoach
186
10k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Statistics for Hackers
jakevdp
796
220k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Become a Pro
speakerdeck
PRO
25
5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
loops executing code over and over again Thursday, September 24,
2009
Thursday, September 24, 2009
for loop loop a specified number of times; the only
loop you need to know http://www.w3schools.com/jS/js_loop_for.asp Thursday, September 24, 2009
for (var i=0; i < 5; i++) { // some
code to run } Thursday, September 24, 2009
for (var i=0; i < 5; i++) { // some
code to run } before any loops Thursday, September 24, 2009
for (var i=0; i < 5; i++) { // some
code to run } before each loop Thursday, September 24, 2009
for (var i=0; i < 5; i++) { // some
code to run } after each loop Thursday, September 24, 2009
for (var i=0; 0 < 5; i++) { // i
would be 0 } Thursday, September 24, 2009
for (var i=0; 1 < 5; i++) { // i
would be 1 } Thursday, September 24, 2009
for (var i=0; 2 < 5; i++) { // i
would be 2 } Thursday, September 24, 2009
for (var i=0; 3 < 5; i++) { // i
would be 3 } Thursday, September 24, 2009
for (var i=0; 4 < 5; i++) { // i
would be 4 } Thursday, September 24, 2009
for (var i=0; 5 < 5; i++) { // condition
false so this // would never happen } Thursday, September 24, 2009
for (var i=0; 5 < 5; i++) { // condition
false so this // would never happen } Thursday, September 24, 2009
var colors = ['red', 'green', 'blue']; for(var i=0; i <
colors.length; i++) { colors[i]; } Thursday, September 24, 2009
var colors = ['red', 'green', 'blue']; for(var i=0, length=colors.length; i
< length; i++) { colors[i]; } Thursday, September 24, 2009
var colors = ['red', 'green', 'blue']; var length = colors.length;
for(var i=0; i < length; i++) { colors[i]; } Thursday, September 24, 2009
while loop loop while a condition is true http://www.w3schools.com/JS/js_loop_while.asp Thursday,
September 24, 2009
var i = 0; while (i < 5) { //
some code to run i++; } Thursday, September 24, 2009
var i = 0; while (i < 5) { //
some code to run i++; } before each loop Thursday, September 24, 2009
var i = 0; while (0 < 5) { //
i would be 0 i++; // i would be 1 } Thursday, September 24, 2009
var i = 0; while (1 < 5) { //
i would be 1 i++; // i would be 2 } Thursday, September 24, 2009
var i = 0; while (2 < 5) { //
i would be 2 i++; // i would be 3 } Thursday, September 24, 2009
var i = 0; while (3 < 5) { //
i would be 3 i++; // i would be 4 } Thursday, September 24, 2009
var i = 0; while (4 < 5) { //
i would be 4 i++; // i would be 5 } Thursday, September 24, 2009
var i = 0; while (5 < 5) { //
condition is false so // this would never happen i++; } Thursday, September 24, 2009
var i = 0; while (5 < 5) { //
condition is false so // this would never happen i++; } Thursday, September 24, 2009
for..in loop loop through the properties of an object http://www.w3schools.com/jS/js_loop_for_in.asp
Thursday, September 24, 2009
for (property in object) { // some code here }
Thursday, September 24, 2009
var person = { name: 'John Nunemaker', age: 27, married:
true, cat_owner: 'unfortunately' }; for (property in person) { property; person[property]; } Thursday, September 24, 2009
var person = { name: 'John Nunemaker', age: 27, married:
true, cat_owner: 'unfortunately' }; for (property in person) { property; // ‘name’ person[property]; // ‘John Nunemaker’ } Thursday, September 24, 2009
var person = { name: 'John Nunemaker', age: 27, married:
true, cat_owner: 'unfortunately' }; for (property in person) { property; // ‘age’ person[property]; // 27 } Thursday, September 24, 2009
var person = { name: 'John Nunemaker', age: 27, married:
true, cat_owner: 'unfortunately' }; for (property in person) { property; // ‘married’ person[property]; // true } Thursday, September 24, 2009
var person = { name: 'John Nunemaker', age: 27, married:
true, cat_owner: 'unfortunately' }; for (property in person) { property; // ‘cat_owner’ person[property]; // ‘unfortunately’ } Thursday, September 24, 2009
break break the current loop and continue with code after
loop if any http://www.w3schools.com/jS/js_break.asp Thursday, September 24, 2009
think “stop looping right now” Thursday, September 24, 2009
for (var i=0; i < 5; i++) { if (i
=== 2) { break; } i; } Thursday, September 24, 2009
for (var i=0; 0 < 5; i++) { if (0
=== 2) { // false break; } i; // 0 } Thursday, September 24, 2009
for (var i=0; 0 < 5; i++) { if (0
=== 2) { // false break; } i; // 0 } Thursday, September 24, 2009
for (var i=0; 1 < 5; i++) { if (1
=== 2) { // false break; } i; // 1 } Thursday, September 24, 2009
for (var i=0; 1 < 5; i++) { if (1
=== 2) { // false break; } i; // 1 } Thursday, September 24, 2009
for (var i=0; 2 < 5; i++) { if (2
=== 2) { // true break; // breaks out of loop } i; // never gets here } Thursday, September 24, 2009
for (var i=0; 2 < 5; i++) { if (2
=== 2) { // true break; // breaks out of loop } i; // never gets here } Thursday, September 24, 2009
most common use is switch statement, but good to know
it works elsewhere Thursday, September 24, 2009
continue break the current loop and continue with the next
value http://www.w3schools.com/jS/js_break.asp Thursday, September 24, 2009
think “skip current loop” Thursday, September 24, 2009
for (var i=0; i < 3; i++) { if (i
=== 1) { continue; } i; // comment } Thursday, September 24, 2009
for (var i=0; 0 < 3; i++) { if (0
=== 1) { // false continue; } i; // 0 } Thursday, September 24, 2009
for (var i=0; 0 < 3; i++) { if (0
=== 1) { // false continue; } i; // 0 } Thursday, September 24, 2009
for (var i=0; 1 < 3; i++) { if (1
=== 1) { // true continue; } i; // never gets here } Thursday, September 24, 2009
for (var i=0; 1 < 3; i++) { if (1
=== 1) { // true continue; } i; // never gets here } Thursday, September 24, 2009
for (var i=0; 2 < 3; i++) { if (2
=== 1) { // false continue; } i; // 2 } Thursday, September 24, 2009
for (var i=0; 2 < 3; i++) { if (2
=== 1) { // false continue; } i; // 2 } Thursday, September 24, 2009
for (var i=0; 3 < 3; i++) { // never
gets here if (i === 1) { continue; } i; } Thursday, September 24, 2009
for (var i=0; 3 < 3; i++) { // never
gets here if (i === 1) { continue; } i; } Thursday, September 24, 2009
assignment04 http://teaching.johnnunemaker.com/capp-30550/sessions/looping/ Thursday, September 24, 2009