The if Statement : If : Statement C# Examples


C# Examples » Statement » If »

 

The if Statement





You can selectively execute part of a program through the if statement.
Its simplest form is shown here:




    
if(condition)  
      statement;
    
   
  
   


condition is a Boolean (that is, true or false) expression.
If condition is true, then the statement is executed.
If condition is false, then the statement is bypassed.

The complete form of the if statement is




    
if(condition)  
      statement;  
else  
      statement;
    
   
  
   

The general form of the if using blocks of statements is




    
if(condition)
{
        statement  sequence  
}
else
{
        statement  sequence  
}
    
   
  
   

if-else-if ladder. It looks like this:




    
if(condition)
      statement;  
else  if(condition)
      statement;  
else  if(condition)
      statement;  
.
.
.
else
      statement;
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Statement
» If