Loop Control Statements

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
$99.99
List Price:  $139.99
You save:  $40
€87.14
List Price:  €122
You save:  €34.86
£75.29
List Price:  £105.41
You save:  £30.12
CA$137.33
List Price:  CA$192.27
You save:  CA$54.93
A$141.80
List Price:  A$198.53
You save:  A$56.72
S$128.26
List Price:  S$179.57
You save:  S$51.31
HK$783.27
List Price:  HK$1,096.61
You save:  HK$313.34
CHF 79.54
List Price:  CHF 111.36
You save:  CHF 31.82
NOK kr958.19
List Price:  NOK kr1,341.51
You save:  NOK kr383.31
DKK kr651.09
List Price:  DKK kr911.55
You save:  DKK kr260.46
NZ$171.92
List Price:  NZ$240.70
You save:  NZ$68.77
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,287.30
List Price:  ৳17,202.71
You save:  ৳4,915.41
₹9,325.70
List Price:  ₹13,056.36
You save:  ₹3,730.65
RM393.91
List Price:  RM551.49
You save:  RM157.58
₦136,279.37
List Price:  ₦190,796.57
You save:  ₦54,517.20
₨27,955.36
List Price:  ₨39,138.62
You save:  ₨11,183.26
฿3,286.67
List Price:  ฿4,601.47
You save:  ฿1,314.80
₺4,431.56
List Price:  ₺6,204.36
You save:  ₺1,772.80
B$524.65
List Price:  B$734.54
You save:  B$209.88
R1,691.56
List Price:  R2,368.26
You save:  R676.69
Лв170.44
List Price:  Лв238.62
You save:  Лв68.18
₩149,919.27
List Price:  ₩209,892.98
You save:  ₩59,973.70
₪311.64
List Price:  ₪436.31
You save:  ₪124.66
₱6,013.19
List Price:  ₱8,418.71
You save:  ₱2,405.51
¥15,910.69
List Price:  ¥22,275.60
You save:  ¥6,364.91
MX$1,779.28
List Price:  MX$2,491.07
You save:  MX$711.78
QR365.84
List Price:  QR512.19
You save:  QR146.35
P1,364.45
List Price:  P1,910.29
You save:  P545.83
KSh12,958.70
List Price:  KSh18,142.70
You save:  KSh5,184
E£5,222.91
List Price:  E£7,312.29
You save:  E£2,089.37
ብር15,710.10
List Price:  ብር21,994.78
You save:  ብር6,284.67
Kz91,203.97
List Price:  Kz127,689.21
You save:  Kz36,485.24
CLP$91,407.85
List Price:  CLP$127,974.65
You save:  CLP$36,566.80
CN¥689.98
List Price:  CN¥966
You save:  CN¥276.02
RD$6,082.91
List Price:  RD$8,516.33
You save:  RD$2,433.41
DA13,238.41
List Price:  DA18,534.30
You save:  DA5,295.89
FJ$221.85
List Price:  FJ$310.60
You save:  FJ$88.75
Q767.07
List Price:  Q1,073.94
You save:  Q306.86
GY$20,949.93
List Price:  GY$29,330.74
You save:  GY$8,380.81
ISK kr12,478.75
List Price:  ISK kr17,470.75
You save:  ISK kr4,992
DH941.49
List Price:  DH1,318.13
You save:  DH376.63
L1,752.37
List Price:  L2,453.39
You save:  L701.02
ден5,371.73
List Price:  ден7,520.65
You save:  ден2,148.91
MOP$808.41
List Price:  MOP$1,131.81
You save:  MOP$323.39
N$1,679.42
List Price:  N$2,351.26
You save:  N$671.83
C$3,679.63
List Price:  C$5,151.64
You save:  C$1,472
रु14,857.69
List Price:  रु20,801.36
You save:  रु5,943.67
S/343.57
List Price:  S/481.02
You save:  S/137.44
K434.10
List Price:  K607.76
You save:  K173.66
SAR375.47
List Price:  SAR525.67
You save:  SAR150.20
ZK1,958.19
List Price:  ZK2,741.54
You save:  ZK783.35
L444.15
List Price:  L621.83
You save:  L177.68
Kč2,135.46
List Price:  Kč2,989.72
You save:  Kč854.26
Ft34,228.72
List Price:  Ft47,921.58
You save:  Ft13,692.86
SEK kr939.65
List Price:  SEK kr1,315.54
You save:  SEK kr375.89
ARS$139,437.37
List Price:  ARS$195,217.90
You save:  ARS$55,780.52
Bs691.96
List Price:  Bs968.77
You save:  Bs276.81
COP$371,588.45
List Price:  COP$520,238.70
You save:  COP$148,650.24
₡46,992.08
List Price:  ₡65,790.80
You save:  ₡18,798.71
L2,655.43
List Price:  L3,717.71
You save:  L1,062.28
₲647,191.03
List Price:  ₲906,093.33
You save:  ₲258,902.30
$U4,049.61
List Price:  $U5,669.62
You save:  $U1,620
zł372.90
List Price:  zł522.07
You save:  zł149.17
Already have an account? Log In

Transcript

Hello, in this video, we are going to look at the control statement that you can use when looking at loops. So there's two control segments. There's the break statement and the continue statement. So let's cover the break statement. First. These are used within loops, they can be used within the for loop Do you want to or the do while loop, it doesn't actually matter, I want to keep it simple.

Get rid of all the loops kolaks that the usage is exactly the same in each one here to that we don't make it out. So run it just to make sure that you know what others do. And just to keep it simple code prints zero to nine who started zero, and its wall is less than 10. Not while I use less than or equal to 10. So the break thing what that does is it breaks the loop so it stops the loop from work. If I do great here.

Let's see what we get. So princess zero. So what happens is it goes through here and even It even moaned about this he says, dead code and the reason is dead code is because it will break at the end of the first pass. So, it declares our AI at zero while I just in time which it is i plus plus at the end of each pass, so it prints out all which is zero don't break. So basically exits the for loop, probably want to use exactly like if you might have some sort of condition like if, if I equals eight, then you might do a break. Break.

It does break like so. So it prints zero to eight, but it doesn't print the final value. So that's what break is the continue statement. What that does is it just skips the current path in the loop. And it continues with Dean Next pass. And if I duplicate this, now we'll actually comment this out as well, like so.

So instead, what we're going to do is let's see if we change this to five. And if I change this to continue instead, as you can see it has 012345678, we have the end of the loop, sorry, because it's at the end of the loop, it's going to go to the next iteration and it's a pretty before the print line. As exists skip five, so 0123 and four, then always five, it's a if i equal five, which it does, then continue so that means skip the rest of the path. Go back to the start, but before it is actually technically ended the past increments. So oiss six goes Here again, is our equal to six No. So it printed out 778 and nine.

And that's it for control statements. Those are the two control statements in Java and pretty much every other coding language. If you have any questions about their use cases, feel free to reach out and unusual. I look forward to seeing you in the next awesome Java video.

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.