Soyoucouldsayifyoutakeout $100 loanwith 5% interestthanthetotalthatyou'll O inthefirstyearwillbe, ah, $105.
Andthenwhatyoucandowith a loopisyoucansaytheninthesecondyearandbeouton $105 plus 5% whateverthatisinthesecondyear, thethirdyear, thefourthyearofthefifthyear, thattypeofthing.
Soifyou'relookingforthingslikeifyou'relookingtotrackthingslongitudeearly, orbeabletoshowthatthat's oneofreasonsthatyouwoulduse a looporanotherreasonthatyouwoulduse a loopisifyou'regoingtobedoing a reportoutofsomethinglike a databaseor a file.
Soifyou'regoingtobepulledpullingmultiplerecordsoutof a databaseorfileandthenyou'regoingtoprintingthatout, whatyouwoulddiois, basically, youwouldsay, Printthisinformationforthefirstlinefrom a fileandthenloop.
Continuetodothatuntilyougettotheendofthefile.
Soloopsairjust a simplewaytodo a repetitivetaskuntil a certainconditionendsupbeingtrue.
Manytimes, peopledecidetouse a fourloopsoffour.
Loopisoneofthestandardloops.
There's also a do, andtheydowildloop.
But a lotofpeople, especiallyforsimpletasks, todecidethatusing a fourloopisthebestwaytogo, sothatlet's gooverthecomputerso I canshowyouwhat a fourlooplookslike.
Sothisis a simplescripttoshowyouhowthefourloopsworks.
Andsothisrightherereallyisallthereisto a fourloop.
Sothefirstthingthatwe'regoingtosayisfour f o.
R.
Afterthat, we'regoingtoopen a parentheses, E, andthenwe'regoingtogivethisfourloopthreedifferentarguments.
Sothefirstthingthatwe'regoingtosayiswe'regoingtoforthisparticularscriptiswe'regoingtocreate a variablecalled X, andwe'regoingtosetthevalueofthatvariabletoone.
Remember, basically, anytimethatyoukindofthinkthat, like a lineofcodeshouldend a lotoftimesyou'lluse a semicolon.
Soyouput a semicolonherewherewegotothenextargument.
Thenwhatwe'regoingtosayisforthatvariablethatwejustcreatedDollarside X, whiledollarSign X islessthanorequalto 20.
Wewantthislooptocontinue, sowe'regoingtoset.
We'regoingtocreateandsetthevalueofvariable X toone, andthenwhile X islessthanorequalto 20 wewantthisscripttocontinueandinthefinalargumenthereagain, after a semicolonis, we'regoingtosaydollarsign X plusplus.
Sowhatthisdoesisthistakesthevalueof X.
Itaddsonetothevalueof X andthensetsthevalueof X tothatnewnumber.
Sohere, soinitially, X equalsone.
Sowhat X Plusdollarsign?
X Plusplusdoesisitsays X plusoneessentiallysetsto X.
Sooneplusoneisnowthevalueofdollarsign X.
Sonowit's twothan X plus, plusthenextiterationitwillbetwoplusone.
Sothendollarsign X willbeworththreeandthenfourandthenfiveandthensix.
Wecouldjustsimplycallthevariable X, butthensetitoutsidesowecouldhavewecouldcreate X saiditto, youknow, fiveupheresaiditto a value.
Andthisisanotherwaythatwecouldrunthefourloop.
Sothisthisis a waythatlet's say, ifyou'regrabbinginformationfrom a formoryou'regrabbinginformationfromsomethingelse, thisis a wayyoucancreateandsetthevalueofthevariablefromtheoutputofsomething, whetherit's a database, whetherit's a form, whetherit's a file, thenoncethishasbeencreatedandset, thenitcouldbegiventothisloop.
Butwherethisreallybecomesvaluableiswhenyoustartreadingtofilesorwhenyoustartinputtingdataintwofilesordatabases, youcanusesomethinglike a fourlooptopullinformationout, dependingondifferentvariables.
Sothat's what a fourloopis, andthat's whytheymatter.
Solet's talkaboutfourloopsinPHP.
Subtitles and vocabulary
Click the word to look it upClick the word to find further inforamtion about it