Python for .NET Developers Transcripts
Chapter: The Python Language
Lecture: C# loops

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Next thing in C# I want to look at and then create in Python is loops, different kinds of loops and iterations and things like that.
0:08 So here we have a simple C# program and it's going to start having a loop here. It's going to come through and say
0:16 while true, it's going to ask the user, what is your name and it's going to greet them as long as they enter a name.
0:22 If they don't, it's going to break out. I guess we could really shorten this if we wanted as Visual Studio was suggesting, there we go.
0:32 I just want to read it in, check it, and break out. We're also then going to take an integer array here.
0:39 We have a pre-defined nums, it contains a bunch of integers. 1, 5, 8, 10 and so on. And we're going to use one of the nicest features
0:46 of C# in terms of iteration stuff, I believe is the foreach loop, right? So much better than the for loop, which is down here.
0:55 So in the foreach loop, we're just going to round. The next number is this. But it has some shortcomings
0:59 like maybe I want to say the first number is this the second number is that, the third number is that. We're going to fall back to our for loop
1:06 and get that number, but also have the index say the first, second, and so on. Let's just run this program real quick.
1:11 I changed program over here CS in this project to run that one. We run it. It says, what is your name? Remember, it's going to ask me my name
1:19 and keep greeting me as long as I say a name so I'll say my name is Michael. My name is Zoe. And if I'm done, I hit Enter.
1:26 It's going to go to the next section and just work with the foreach loops. So here it loops through those numbers.
1:31 The next number is 1, 5, 8, 10, 7, 2, great. The next, next, next, how great is that? We said no, no, no. We're going to use a for loop
1:39 and we're going to have the first number as 1 the second number is 5 now obviously it should be first, not firth
1:45 or however you pronounce that right there. But we're not going to sweat the details. We could obviously add that adjustment
1:52 for the suffix of these letters but first is 1, second is 5, third, 8, and so on. This project in C# works with most
2:02 of the structures of looping that we have in the language.


Talk Python's Mastodon Michael Kennedy's Mastodon