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

Conditional statements in C#

Прочитайте:
  1. Jump 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

Conditional statements allow you to branch your code depending on whether certain conditions are met or on the value of an expression. Conditional Statements are basic building blocks of program that controls the flow of a program. It executes a particular block of statement based on a Boolean condition, which is an expression returning true or false. These are statements are also known as Decision making statements. Therefore, conditional statements allow you to take logical decisions about executing different block of program to achieve the required logical output. C# supports various types of conditional Statements they are as follows.

if statement will evaluate the condition. If it is true, it will execute the statements that follow it. Otherwise, it will leave the block of statements that are followed by it.
Simple e.g. I will go to market if got time. So, here time is the constraints that will evaluated. If I have time this will be true then only will go to market.

If(condition){ //block of statements}

if else statement will evaluate the condition. If condition is true, it will execute the statements that follow if block. Otherwise, it will execute the statements that are followed by else block.
Simple e.g. I will go to market if got time else I will be at home. So, here time is the constraints that will evaluated first.If I got time then I will be at market else I will be at home.

If(condition){ //block of statements}

else(condition){ //block of statements}

Ternary Operator. The conditional operator behaves like a simple if…else statement.

Condition? Statement1: Statement 2

The compiler will first evaluate the condition. If the Condition is true, then it will execute statement 1, otherwise it will execute statement 2.

 


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



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 сек.)