АкушерствоАнатомияАнестезиологияВакцинопрофилактикаВалеологияВетеринарияГигиенаЗаболеванияИммунологияКардиологияНеврологияНефрологияОнкологияОториноларингологияОфтальмологияПаразитологияПедиатрияПервая помощьПсихиатрияПульмонологияРеанимацияРевматологияСтоматологияТерапияТоксикологияТравматологияУрологияФармакологияФармацевтикаФизиотерапияФтизиатрияХирургияЭндокринологияЭпидемиология

Jump statements in C#

Прочитайте:
  1. Conditional statements in C#.
  2. XV. Decide whether these statements are true of false. Use: ”You are (not quite) right; you are mistaken. That’s (not quite) right“ and give the right answer.
  3. XVII. Decide whether the following statements are false or true. Use: ”You are (not quite) right; you are mistaken. That’s (not quite) right“ and give the right answer

There are five types of jump statements used in C# as follows: Goto, Break,Continue, Return,Throw.

The goto statement allows you to jump directly to another specified line in the program, indicated by a label: goto Label1; Console.WriteLine("This won't be executed"); Label1: Console.WriteLine("Continuing execution from here");

A couple of restrictions are involved with goto. You can’t jump into a block of code such as a for loop, you can’t jump out of a class, and you can’t exit a finally block after try.catch blocks. The reputation of the goto statement probably precedes it, and in most circumstances, its use is sternly frowned upon. In general, it certainly doesn’t conform to good object-oriented programming practice. break statement —. Control will switch to the statement immediately after the end of the loop. If the statement occurs in a nested loop, control will switch to the end of the innermost loop. If the break occurs outside of a switch statement or a loop, a compile-time error will occur. The break will exit only a single loop iteration. The continue statement is similar to break, and must also be used within a for, foreach, while, or do...while loop. However, it exits only from the current iteration of the loop, meaning that execution will restart at the beginning of the next iteration of the loop, rather than outside the loop altogether. It is used to transfer the program control to the beginning of the loop. It continues until a specific condition is satisfied; in other words, the continue statement skips the remaining code in the loop and the pointer is sent to the beginning of the loop. The continue statement tells the complier to skip the following statements and continue with the next iteration. The return statement is used to exit a method of a class, returning control to the caller of the method. If the method has a return type, return must return a value of this type; otherwise if the method returns void, you should use return without an expression.

 


Дата добавления: 2015-09-18 | Просмотры: 601 | Нарушение авторских прав



1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |



При использовании материала ссылка на сайт medlec.org обязательна! (0.003 сек.)