Object
Object
Control statements are those that alter the order in which statements are executed. For instance,
statements like If, If-else, Switch-Case, and while-do. Boolean expressions are utilized in
computer programming languages to Boolean expressions are employed as conditional
expressions in a statement to change the direction of control. Such a Boolean expression's value
is inherent in the place that the programme has reached. For instance, if statement S is reached,
then the expression E should be true. Determine logical values A Boolean expression can specify
values as true or false. Using three address instructions and logical operators, these Boolean
expressions can be computed concurrently with arithmetic expression. The grammatical context
of the Boolean expression determines its intended application.
i) It is always legal in C programming to nest if-else statements, which means you can use
one if or else if statement inside another if or else if statement(s).
Syntax
The syntax for a nested if statement is as follows −
if( Boolean expression 1) {
You can nest else if...else in the similar way as you have nested if statements.
Example
#include <stdio.h>
int main () {
return 0;
}
When the above code is compiled and executed, it produces the following result −
Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200
Syntax of switch...case
switch (expression)
{
case constant1:
// statements
break;
case constant2:
// statements
break;
.
.
.
default:
// default statements
}
The expression is evaluated once and compared with the values of each case label.
• If there is a match, the corresponding statements after the matching label are executed.
For example, if the value of the expression is equal to constant2, statements after case
constant2: are executed until break is encountered.
• If there is no match, the default statements are executed.
b) Iteration is a method used in computer programming where a sequence of instructions or
structures are repeated until a condition is satisfied or a predetermined number of times. An
iteration is the process of repeating the first set of instructions. A loop is defined as the repeating
execution of a set of instructions.
Iteration is the repetition of a process in a computer program, usually done with the help of
loops.
An example of an iteration programming language is as follows:
Consider a database table containing 1000 student records. Each record contains the following
fields:
• First name
• Last name
• Roll no
If one wants to copy all the student records from the database and print them, the best way to
retrieve the record is to iterate or loop through each record. It can be executed using the for loop
statement as shown below:
for (int i=0;i<1000;i++)
{
Print first name and last name from table
}
In the above example, i is an iterator starting from the first student record to the last student
record.
I. A while loop in C programming repeatedly executes a target statement as long as a given
condition is true.
Syntax
The syntax of a while loop in C programming language is −
while(condition) {
statement(s);
}
Here, statement(s) may be a single statement or a block of statements. The condition may be any
expression, and true is any nonzero value. The loop iterates while the condition is true.
When the condition becomes false, the program control passes to the line immediately following
the loop.
II. Unlike for and while loops, which test the loop condition at the top of the loop, the
do...while loop in C programming checks its condition at the bottom of the loop.
A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least
one time.
Syntax
The syntax of a do...while loop in C programming language is −
do {
statement(s);
} while( condition );
Notice that the conditional expression appears at the end of the loop, so the statement(s) in the
loop executes once before the condition is tested. If the condition is true, the flow of control jumps
back up to do, and the statement(s) in the loop executes again. This process repeats until the given
condition becomes false.
2.
Java's static keyword is mostly utilised for memory management. With variables, methods, blocks,
and nested classes, the static keyword can be used. The static keyword is a property of the class
rather than a class instance.
This static could be:
1. Variable (also called as a class variable)
2. Method (often referred to as a class method)
3.Block
4.Nest class
Static Java variable
A variable is considered static if you declare it to be static. The common characteristic shared by
all objects, which is not specific to each object, can be referred to by the static variable, for
instance, the name of the employer for employees, the name of the college for students, etc. When
the class is loaded, the static variable only receives one memory allocation in the class area.
The appropriate `add()` method is selected based on the argument types provided during the
function call.