While Loop

3 minutes
Share the link to this page
Copied
  Completed
Learn about the wonderful simplicity of while loops.

Transcript

Hello, welcome to the 11th tutorial in the swift basic series and in this part we're going to be looking at the world loop. So let's open up our project loops live code to be repeated helping reduce code this could be for for example, if you have an array of high school that you want to print out to schools, we did this in the non tutorial with the for loop. The while loop is slightly different. As I show you the main difference is on what is it? That's a word it's going to create an array called High School, make it equal to the following values 187 34 five and 040 I'm gonna write it out and then it's been explained to you exactly what it is and how it works is done for you Print and school backslash backslash life goals. Now let's let's run this and let's see the result.

Okay meters get out the console window so you never run it again and see yes, it does score 100 score to excellent score 334 score four, five, score five zero on the form where you would actually set up the iterator inside the loop at start, you set up the condition and you set up the thing that sort of affects the twist. So you have three main parts the first thing, the while the only necessity is the condition Essentially assumes that you set to any variable before this is great if you use no variable for something else. So the wall loop is good for that. Also, it assumes that you're going to be affecting it or you don't need maybe you don't need to affect it at the end of each iteration if you do you do within the loop, the loop only takes one condition like I said any variable setup is done before anything and anything that changes the variables that are part of the condition are changed in the loop usually at the end.

The brackets for the for for the while loop are not necessarily but recommend that they help maintain the code readability aka I can remove these racket still run it anywhere today. Okay, but it just helps with the readability of the code. So that's it for this tutorial. The next tutorial we're going to look at the do while loop if you have any questions feel free to message us at support at sono system calm okay. The email will be in the description you can comment on this video or during messages via YouTube or the requiring full source code loss of in the description. Hope you enjoyed this video and have a nice day

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.