Do While Loops

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$39.99
List Price:  $79.99
You save:  $40
€34.07
List Price:  €68.15
You save:  €34.08
£29.90
List Price:  £59.81
You save:  £29.91
CA$55.10
List Price:  CA$110.22
You save:  CA$55.11
A$60.11
List Price:  A$120.24
You save:  A$60.13
S$51.67
List Price:  S$103.35
You save:  S$51.68
HK$311.07
List Price:  HK$622.23
You save:  HK$311.15
CHF 31.83
List Price:  CHF 63.67
You save:  CHF 31.83
NOK kr405.39
List Price:  NOK kr810.89
You save:  NOK kr405.49
DKK kr254.40
List Price:  DKK kr508.88
You save:  DKK kr254.47
NZ$68.90
List Price:  NZ$137.81
You save:  NZ$68.91
د.إ146.86
List Price:  د.إ293.76
You save:  د.إ146.90
৳4,879.28
List Price:  ৳9,759.79
You save:  ৳4,880.50
₹3,622.47
List Price:  ₹7,245.85
You save:  ₹3,623.38
RM163.85
List Price:  RM327.74
You save:  RM163.89
₦57,951.34
List Price:  ₦115,917.17
You save:  ₦57,965.83
₨11,189.43
List Price:  ₨22,381.66
You save:  ₨11,192.23
฿1,257.46
List Price:  ฿2,515.23
You save:  ฿1,257.77
₺1,702.77
List Price:  ₺3,405.97
You save:  ₺1,703.19
B$216.72
List Price:  B$433.49
You save:  B$216.77
R674.84
List Price:  R1,349.86
You save:  R675.01
Лв66.64
List Price:  Лв133.31
You save:  Лв66.66
₩58,966.45
List Price:  ₩117,947.65
You save:  ₩58,981.20
₪128.88
List Price:  ₪257.80
You save:  ₪128.91
₱2,364
List Price:  ₱4,728.60
You save:  ₱2,364.60
¥6,228.64
List Price:  ¥12,458.84
You save:  ¥6,230.19
MX$720.37
List Price:  MX$1,440.93
You save:  MX$720.55
QR145.51
List Price:  QR291.06
You save:  QR145.55
P529.02
List Price:  P1,058.17
You save:  P529.15
KSh5,148.59
List Price:  KSh10,298.48
You save:  KSh5,149.88
E£1,892.06
List Price:  E£3,784.60
You save:  E£1,892.53
ብር6,238.54
List Price:  ብር12,478.64
You save:  ብር6,240.10
Kz36,670.83
List Price:  Kz73,350.83
You save:  Kz36,680
CLP$36,502.89
List Price:  CLP$73,014.92
You save:  CLP$36,512.02
CN¥282.10
List Price:  CN¥564.28
You save:  CN¥282.18
RD$2,538.21
List Price:  RD$5,077.05
You save:  RD$2,538.84
DA5,185.10
List Price:  DA10,371.51
You save:  DA5,186.40
FJ$90.84
List Price:  FJ$181.72
You save:  FJ$90.87
Q305.81
List Price:  Q611.69
You save:  Q305.88
GY$8,353.11
List Price:  GY$16,708.30
You save:  GY$8,355.19
ISK kr5,045.77
List Price:  ISK kr10,092.81
You save:  ISK kr5,047.03
DH367.32
List Price:  DH734.73
You save:  DH367.41
L674.94
List Price:  L1,350.06
You save:  L675.11
ден2,095.59
List Price:  ден4,191.71
You save:  ден2,096.12
MOP$320.16
List Price:  MOP$640.40
You save:  MOP$320.24
N$673.61
List Price:  N$1,347.40
You save:  N$673.78
C$1,469.47
List Price:  C$2,939.31
You save:  C$1,469.83
रु5,777.17
List Price:  रु11,555.79
You save:  रु5,778.62
S/134.42
List Price:  S/268.88
You save:  S/134.45
K172.10
List Price:  K344.25
You save:  K172.15
SAR150.05
List Price:  SAR300.13
You save:  SAR150.08
ZK921.31
List Price:  ZK1,842.85
You save:  ZK921.54
L173.39
List Price:  L346.82
You save:  L173.43
Kč826.55
List Price:  Kč1,653.32
You save:  Kč826.76
Ft13,062.16
List Price:  Ft26,127.58
You save:  Ft13,065.42
SEK kr370.70
List Price:  SEK kr741.49
You save:  SEK kr370.79
ARS$57,340.81
List Price:  ARS$114,695.95
You save:  ARS$57,355.14
Bs275.88
List Price:  Bs551.83
You save:  Bs275.95
COP$152,061.07
List Price:  COP$304,160.17
You save:  COP$152,099.10
₡19,972
List Price:  ₡39,949
You save:  ₡19,977
L1,051.16
List Price:  L2,102.60
You save:  L1,051.43
₲268,190.58
List Price:  ₲536,448.22
You save:  ₲268,257.64
$U1,566.95
List Price:  $U3,134.29
You save:  $U1,567.34
zł143.79
List Price:  zł287.63
You save:  zł143.83
Already have an account? Log In

Transcript

There is a third loop in JavaScript called do while loop. And what the do while loop does is that it executes the code at least once, regardless of the condition. So for example, if we take a look at the do while loop, I'm going to comment these out first. And I'm going to create a do while loop until you either do while loop. What you are going to do is you just create do and then curly braces, and then inside those do inside those curly braces, you add your code, and then you type while and then the condition and cynical. So the condition here should be for example, it could be three at first, a variable called x ln x equals 10.

Right? And then here inside the while loop, I'm going to add if x is smaller than 10. As you can see here, the condition is violated because x equals to 10. But here says if x is smaller than 10. and here if I add a code like console dot log, and then Hi, john, john, and if I save and run, I am going to get hi john, only once because it's first going to get to the do loop, do condition and implement this code and then it is going to take a look at the while loop. If the while loop is met, if the while loop condition is met, it's going to go back again and excute what is inside the do curly braces, but if the condition is violated will not continue and it's gonna move on and get out of the loop. So for example, if I change the value of x from 10 to zero, and then here I increase the x by one x plus plus, and if I save and run, I am going to get x, I am going to get hi john printed out on the screen 10 times, because here it does the same to it's gonna get executed, this code is going to get executed 10 times because it was going to get into the do and print out this line of code and then it's going to increase the value of x.

And then it's going to get to the wild loop and check the condition if the condition is still there. It is is still met, we are going to get again back to the do condition or the do code and implement the code again and increase x and so on and so forth. So do why loops get executed at least once.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.