What Is Unconditional Branching?
What Is Unconditional Branching?
What Is Unconditional Branching?
Conditional branch, A programming instruction that directs the computer to another part of the
program based on the results of a compare. High-level language statements, such as IF THEN
ELSE and CASE, are used to express the compare and conditional branch.
What is unconditional branching?
Unconditional branching is when the programmer forces the execution of a program to jump to
another part of the program. Theoretically, this can be done using a good combination of loops and
if statements. In fact, as a programmer, you should always try to avoid such unconditional
branching and use this technique only when it is very difficult to use a loop.The goto statement is
used for unconditional branching or transfer of the program execution to the labeled statement.
What is an array?
Arrays a kind of data structure that
can store a fixed-size sequential
collection of elements of the same type. An array is used to store a collection of data, but it is often
more useful to think of an array as a collection of variables of the same type.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you
declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99]
to represent individual variables. A specific element in an array is accessed by an index.All arrays
consist of contiguous memory locations. The lowest address corresponds to the first element and
the highest address to the last element.
To declare an array a programmer specifies the type of the elements and the number of elements
required by an array as follows −
type arrayName [ arraySize ];
If-else statement
This is how an if-else statement looks:
if(condition) {
Statement(s);
}
else {
Statement(s);
}
The statements inside “if” would execute if the condition is true, and the statements inside “else”
would execute if the condition is false.
Example:
class Day {
public static void
main(String[] args) {
int week = 4;
String day;
switch (week) {
case 1:
day = "Sunday";
break;
case 2:
day = "Monday";
break;
case 3:
day = "Tuesday";
break;
case 4:
day = "Wednesday";
break;
case 5:
day = "Thursday";
break;
case 6:
day = "Friday";
break;
case 7:
day = "Saturday";
break;
default:
day = "Invalid day";
break;
}
System.out.println(day);
}
}
Output:
Wednesday
Example:
class WhileLoopExample {
public static void main(String
args[]){
int i=10;
while(i>1){
System.out.println(i);
i--;
}
}
}
Example:
class DoWhileLoopExample {
public static void main(String args[]){
int i=10;
do{
System.out.println(i);
i--;
}while(i>1);
}
}
First step: In for loop, initialization happens first and only one time, which means that the
small = arr[0];