The For Loop

1 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€42.52
List Price:  €59.53
You save:  €17.01
£37.27
List Price:  £52.19
You save:  £14.91
CA$68.86
List Price:  CA$96.41
You save:  CA$27.55
A$75.34
List Price:  A$105.49
You save:  A$30.14
S$64.47
List Price:  S$90.27
You save:  S$25.79
HK$388.86
List Price:  HK$544.44
You save:  HK$155.57
CHF 39.78
List Price:  CHF 55.69
You save:  CHF 15.91
NOK kr508.40
List Price:  NOK kr711.80
You save:  NOK kr203.40
DKK kr317.68
List Price:  DKK kr444.77
You save:  DKK kr127.09
NZ$86.44
List Price:  NZ$121.02
You save:  NZ$34.58
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,107.52
List Price:  ৳8,551.02
You save:  ৳2,443.49
₹4,549.73
List Price:  ₹6,369.99
You save:  ₹1,820.25
RM204.23
List Price:  RM285.94
You save:  RM81.71
₦72,591.97
List Price:  ₦101,634.57
You save:  ₦29,042.60
₨14,005.97
List Price:  ₨19,609.48
You save:  ₨5,603.51
฿1,575.72
List Price:  ฿2,206.14
You save:  ฿630.41
₺2,135.21
List Price:  ₺2,989.46
You save:  ₺854.25
B$270.67
List Price:  B$378.96
You save:  B$108.29
R839.85
List Price:  R1,175.86
You save:  R336
Лв83.15
List Price:  Лв116.42
You save:  Лв33.27
₩73,708.76
List Price:  ₩103,198.16
You save:  ₩29,489.40
₪160.81
List Price:  ₪225.14
You save:  ₪64.33
₱2,930.02
List Price:  ₱4,102.27
You save:  ₱1,172.24
¥7,740.31
List Price:  ¥10,837.05
You save:  ¥3,096.74
MX$898.20
List Price:  MX$1,257.56
You save:  MX$359.35
QR182.14
List Price:  QR255.01
You save:  QR72.87
P660.05
List Price:  P924.12
You save:  P264.07
KSh6,443.71
List Price:  KSh9,021.71
You save:  KSh2,578
E£2,369.56
List Price:  E£3,317.57
You save:  E£948.01
ብር7,778.43
List Price:  ብር10,890.43
You save:  ብር3,111.99
Kz45,607.28
List Price:  Kz63,853.85
You save:  Kz18,246.56
CLP$45,707.35
List Price:  CLP$63,993.95
You save:  CLP$18,286.60
CN¥352.01
List Price:  CN¥492.84
You save:  CN¥140.83
RD$3,174.56
List Price:  RD$4,444.65
You save:  RD$1,270.08
DA6,479.50
List Price:  DA9,071.82
You save:  DA2,592.32
FJ$112.66
List Price:  FJ$157.74
You save:  FJ$45.07
Q382.83
List Price:  Q536
You save:  Q153.16
GY$10,455.70
List Price:  GY$14,638.82
You save:  GY$4,183.11
ISK kr6,301.73
List Price:  ISK kr8,822.93
You save:  ISK kr2,521.20
DH458.73
List Price:  DH642.26
You save:  DH183.52
L841.87
List Price:  L1,178.68
You save:  L336.81
ден2,617.77
List Price:  ден3,665.09
You save:  ден1,047.32
MOP$400.62
List Price:  MOP$560.91
You save:  MOP$160.28
N$838.51
List Price:  N$1,173.99
You save:  N$335.47
C$1,839.31
List Price:  C$2,575.18
You save:  C$735.87
रु7,252.24
List Price:  रु10,153.72
You save:  रु2,901.48
S/168.29
List Price:  S/235.62
You save:  S/67.33
K212.38
List Price:  K297.36
You save:  K84.97
SAR187.52
List Price:  SAR262.55
You save:  SAR75.02
ZK1,158.20
List Price:  ZK1,621.58
You save:  ZK463.37
L216.50
List Price:  L303.11
You save:  L86.61
Kč1,034.66
List Price:  Kč1,448.60
You save:  Kč413.94
Ft16,368.18
List Price:  Ft22,916.77
You save:  Ft6,548.58
SEK kr464.96
List Price:  SEK kr650.99
You save:  SEK kr186.02
ARS$71,899.03
List Price:  ARS$100,664.40
You save:  ARS$28,765.36
Bs346.59
List Price:  Bs485.26
You save:  Bs138.66
COP$189,678.03
List Price:  COP$265,564.41
You save:  COP$75,886.38
₡24,999.25
List Price:  ₡35,000.95
You save:  ₡10,001.70
L1,316.40
List Price:  L1,843.07
You save:  L526.66
₲335,662.32
List Price:  ₲469,954.11
You save:  ₲134,291.78
$U1,955.72
List Price:  $U2,738.16
You save:  $U782.44
zł179.59
List Price:  zł251.44
You save:  zł71.85
Already have an account? Log In

Transcript

The for loop has a different structure. It allows us to initialize the variable, set a condition and determine the increment or decrement of that variable all at once. Just by observing the robot, we won't be able to tell whether we are running the while or the for loop. This program will also repeat the forward turn right commands four times. In the real robot C program, do take note that we declare and initialize the count variable right inside the for loops brackets. You may ask why we have two ways of doing the same thing, or which loops should be used in what situations?

In many instances, the answer is that it's your choice, but there is a slight difference. The for loop is better when you want a loop to repeat for a known number of times. Because the command interface allows you to define variables and their increment decrement when you write the for loop The while loop is better when you want the loop to continue until some sensor reading is reached. But you don't know how many times that will take. It is better because the loop continuously check a given sensor reading without having to go through the increment decrements stage

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.