课程: Learning C#
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Using break and continue
- All right. So, so far we've seen how the four and wild loop constructs give programs a way to perform a set of instructions repeatedly. And in this example, we're going to learn about two other statements that give you finer grained control over how loops execute. And these are the break and continue statements. So here in my code, in the break continue folder I'm going to open up the program file. So sometimes you want to be able to stop the execution of a loop before the ending condition is reached. So for example, suppose I had a list or an array of integer values, and I wanted to find the first instance of a value that is larger than 40. So I can have a for each loop that iterates over all the values and prints each value. So I can use the break statement, to terminate the loop early like this. So I can write if val is greater than or equal to 40 then break. So I've got my for each loop. It's going to get the…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。