filmov
tv
while loop in java

Показать описание
Java tutorial for beginners playlist
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Syntax:
while (condition) {
statement-1;
statement-2;
:
}
While is entry controlled loop
1. If condition is true, only then statements are executed
2. Loop gets executed zero or more times
3. Loop keeps executing till condition becomes false
4. Do not forget to ensure termination of loop
do while loop syntax:
do {
statement-1;
statement-2;
:
} while (condition);
do-while is exit controlled loop
1. Statements get executed first and then condition gets evaluated
2. If condition is false initially, loop will get executed once
3. Loop keeps executing till condition becomes false
break statement syntax:
break;
1. Gets control out of the loop
2. Breaks out immediately
3. Control falls to statement after loop
4. Stops only the loop in which it resides
continue statement syntax:
continue;
1. Immediately stops current iteration
2. Jumps to next iteration
3. Helps in ignoring certain iterations
We have continue statement in java. The continue keyword can be used in any of the loops. It causes loop to immediately stop the current iteration and immediately jump to next iteration
int sum = 0;
for (int i = 1; i [= 100; i++) {
if (i%2 == 0) {
continue;
}
sum += i;
}
# Program 1
public class BreakDemo {
public static void main(String[] args) {
String string = "This is a long long string";
int numberOfOs = 0;
numberOfOs++;
continue;
}
}
}
}
# Program 2
public class WhileDemo {
public static void printLine() {
int numberOfAsterisks = 50;
while (numberOfAsterisks ]= 0) {
numberOfAsterisks--;
}
}
public static void main(String[] args) {
printLine();
int input;
do {
if (input [= 0) {
}
else if (input%2 == 0) {
}
else {
}
} while (input != -1);
printLine();
}
}
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Syntax:
while (condition) {
statement-1;
statement-2;
:
}
While is entry controlled loop
1. If condition is true, only then statements are executed
2. Loop gets executed zero or more times
3. Loop keeps executing till condition becomes false
4. Do not forget to ensure termination of loop
do while loop syntax:
do {
statement-1;
statement-2;
:
} while (condition);
do-while is exit controlled loop
1. Statements get executed first and then condition gets evaluated
2. If condition is false initially, loop will get executed once
3. Loop keeps executing till condition becomes false
break statement syntax:
break;
1. Gets control out of the loop
2. Breaks out immediately
3. Control falls to statement after loop
4. Stops only the loop in which it resides
continue statement syntax:
continue;
1. Immediately stops current iteration
2. Jumps to next iteration
3. Helps in ignoring certain iterations
We have continue statement in java. The continue keyword can be used in any of the loops. It causes loop to immediately stop the current iteration and immediately jump to next iteration
int sum = 0;
for (int i = 1; i [= 100; i++) {
if (i%2 == 0) {
continue;
}
sum += i;
}
# Program 1
public class BreakDemo {
public static void main(String[] args) {
String string = "This is a long long string";
int numberOfOs = 0;
numberOfOs++;
continue;
}
}
}
}
# Program 2
public class WhileDemo {
public static void printLine() {
int numberOfAsterisks = 50;
while (numberOfAsterisks ]= 0) {
numberOfAsterisks--;
}
}
public static void main(String[] args) {
printLine();
int input;
do {
if (input [= 0) {
}
else if (input%2 == 0) {
}
else {
}
} while (input != -1);
printLine();
}
}
Комментарии