Java tutorial for beginners playlist
• Java tutorial for beginners
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.
/ @aarvikitchen5572
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;
for (int i=0; i[string.length(); i++) {
if (string.charAt(i) == 'o') {
numberOfOs++;
System.out.println(" **** o found");
continue;
}
System.out.println("This is not o");
}
System.out.println("Number of Os " + numberOfOs);
}
}
Program 2
package com.training.java;
import java.util.Scanner;
public class WhileDemo {
public static void printLine() {
int numberOfAsterisks = 50;
while (numberOfAsterisks ]= 0) {
System.out.print("*");
numberOfAsterisks--;
}
System.out.println();
}
public static void main(String[] args) {
printLine();
Scanner scanner = new Scanner(System.in);
int input;
do {
System.out.print("Enter a number (-1 to exit) : ");
input = scanner.nextInt();
if (input [= 0) {
System.out.println("Seems you are not interested !!");
}
else if (input%2 == 0) {
System.out.println("You entered an even number");
}
else {
System.out.println("You enetered an odd number");
}
} while (input != -1);
printLine();
}
}
На этой странице сайта вы можете посмотреть видео онлайн while loop in java длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь kudvenkat 10 Апрель 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 13,536 раз и оно понравилось 54 зрителям. Приятного просмотра!