This document discusses various decision structures and loops in programming. It covers IF/ELSE statements, nested IF statements, ELSE-IF statements, comparing strings, WHILE loops, FOR loops, DO-WHILE loops, and using random numbers. Examples are provided for each to illustrate their usage and applications in controlling program flow and logic.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
90 views30 pages
Decision Structures
This document discusses various decision structures and loops in programming. It covers IF/ELSE statements, nested IF statements, ELSE-IF statements, comparing strings, WHILE loops, FOR loops, DO-WHILE loops, and using random numbers. Examples are provided for each to illustrate their usage and applications in controlling program flow and logic.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30
DECISION
STRUCTURES IF STATEMENT
It is decision structure, which is used
to control the program flow based on some condition. It is used to execute some statement code block if the expression is evaluated to true. Otherwise, it will get skipped. EXAMPLE FOR IF STRUCTURE IF-ELSE STATEMENT
IF-ELSE is a conditional statement
that runs a different set of statements depending on whether an expression is true or false. EXAMPLE FOR IF-ELSE STRUCTURE Nested Decision Structures
A nested if statement is an if statement that's place inside
another, which allows for complex conditions. EXAMPLE OF NESTED IF STRUCTURE ELSE-IF STATEMENTS
Else used also 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; that way, if the first statement is true, the "else if" will be ignored, but if the if statement is false, it will then check the condition for the else if statement. If the if statement was true the else statement will not be checked. EXAMPLE ELSE-IF STATEMENTS COMPARING STRINGS
The simplest form of comparting two string for
the same value is using String.Equals method. If both strings are equal, the method returns true; else returns false.
if (String.Equals (a,b)) EXAMPLE OF COMPARING STRINGS String.Compare
String.Compare method compares two strings and
returns an integer value. The return value of the Compare method can be less than zero, greater than zero or equals to zero. EXAMPLE OF String.Compare CompareTo Method
CompareTo method is an instance method of string
class. It compares a value (either a string or on object) with a string instance. Return values of this method are same as the Compare method. PREVENTING DATA CONVERSION EXCEPTION
TryParse() is similar to Parse() and used to convert string
type to specified numeric type, however if conversion fails then instead of throwing exception, it returns a Boolean value as False.
bool result = Int32.TryParse(string input, out number);
RADIO BUTTONS AND CHECK BOXES
Checkboxes and Radio Buttons are way to offer your
users choices. Radio buttons are used when there is a list of two or more options that are mutually exclusive and the user must select exactly one choice. EXAMPLE OF RADIOBUTTON SWITCH STATEMENT STRUCTURE
A switch statement allows a variable to be tested for
equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case. EXAMPLE OF SWITCH CASE LIST BOXES
ListBox control provides a user interface to display a list
of items. Users can select one or more items from the list. A ListBox may be used to display multiple columns and these columns may have images and other controls. EXAMPLE OF LISTBOX WHILE LOOP
While loop includes a Boolean
expression as a condition which will return true or false. It executes the code block, as long as the specified conditional expression returns true. EXAMPLE WHILE LOOP INFINITE LOOPS
Infinite loops are loops that are repeated until the
program is interrupted. It typically occurs when the programmer made an error in doing the code such as forgetting to write the test condition to make it false. FOR LOOP
For loop is a type of loop construct found
in many procedural languages which repeatedly execute some instructions while a condition is true. EXAMPLE OF FOR LOOP DO-WHILE LOOP
Do-while” loop is used to execute a
block of statements until the specified expression is false. EXAMPLE OF DO-WHILE LOOP Random Numbers
The .Net Framework provides a specific class in
order to generate random numbers. Hence, it is named as the Random Class. It is a type of software routine that is commonly used in applications and cryptographic key generations. EXAMPLE OF RANDOM NUMBER