Basic If else statements
Page 1 of 1
Basic If else statements
The if statement allows you to control if a program enters a section of code or not based on whether a given condition is true or false. One of the important functions of the if statement is that it allows the program to select an action based upon the user's input。
If statements allow the flow of the program to be changed, and so they allow algorithms and more interesting code。
Here are the relational operators:
> greater than
< less than
>= greater than or equal
<= less than or equal
== equal to
!= not equal to
If
The structure of an if statement is as follows:
[You must be registered and logged in to see this image.]
Else
Sometimes when the condition in an if statement evaluates to false, it would be nice to execute some code instead of the code executed when the statement evaluates to true. The "else" statement effectively says that whatever code after it is executed if the if statement is FALSE.
The structure of an else statement is as follows:
[You must be registered and logged in to see this image.]
Else If
Another use of else is when there are multiple conditional statements that may all evaluate to true, yet you want only one if statement's body to execute. You can use an "else if" statement following an if statement and its body.
[You must be registered and logged in to see this image.]
Here’s a simple program:
[You must be registered and logged in to see this image.]
If statements allow the flow of the program to be changed, and so they allow algorithms and more interesting code。
Here are the relational operators:
> greater than
< less than
>= greater than or equal
<= less than or equal
== equal to
!= not equal to
If
The structure of an if statement is as follows:
[You must be registered and logged in to see this image.]
Else
Sometimes when the condition in an if statement evaluates to false, it would be nice to execute some code instead of the code executed when the statement evaluates to true. The "else" statement effectively says that whatever code after it is executed if the if statement is FALSE.
The structure of an else statement is as follows:
[You must be registered and logged in to see this image.]
Else If
Another use of else is when there are multiple conditional statements that may all evaluate to true, yet you want only one if statement's body to execute. You can use an "else if" statement following an if statement and its body.
The structure of an if else is as follows:
[You must be registered and logged in to see this image.]
Here’s a simple program:
[You must be registered and logged in to see this image.]
Rachael_C- Beginner
- Posts : 13
Points : 73221
Reputation : 0
Join date : 2014-04-27
Similar topics
» Basic Loops
» 1-2 Visual Basic .NET Forms
» Visual Basic Tutorial
» Basic Input/Output
» 3 basic concepts you must know about information security
» 1-2 Visual Basic .NET Forms
» Visual Basic Tutorial
» Basic Input/Output
» 3 basic concepts you must know about information security
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|