Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Podcasts & Audio Briefings9to5Google: The Sideload 046: Frictionmaxxing with Allison Johnson(29.09.2026 um 22:31 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Prelaunch News Conference (Sept. 30, 2026)(22.09.2026 um 22:14 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Launch(29.09.2026 um 00:25 Uhr)
•
Windows Tipps & SecurityMicrosoft Releases WSL Containers for Windows 11(29.09.2026 um 22:37 Uhr)
•
Unix & Linux ServerSecurity: Mangelnde Rechteprüfung in KDE Plasma (Ubuntu)(29.09.2026 um 23:50 Uhr)
•
Unix & Linux ServerSecurity: Mehrere Probleme in amazon-cloudwatch-agent (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Pufferüberlauf in corosync (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Ausführen beliebiger Kommandos in perl-DBI (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Zwei Probleme in cjose (SUSE)(30.09.2026 um 00:10 Uhr)
••
Podcasts & Audio Briefings9to5Google: The Sideload 046: Frictionmaxxing with Allison Johnson(29.09.2026 um 22:31 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Prelaunch News Conference (Sept. 30, 2026)(22.09.2026 um 22:14 Uhr)
•
YouTube Security VideosNASA's SpaceX Crew-13 Launch(29.09.2026 um 00:25 Uhr)
•
Windows Tipps & SecurityMicrosoft Releases WSL Containers for Windows 11(29.09.2026 um 22:37 Uhr)
•
Unix & Linux ServerSecurity: Mangelnde Rechteprüfung in KDE Plasma (Ubuntu)(29.09.2026 um 23:50 Uhr)
•
Unix & Linux ServerSecurity: Mehrere Probleme in amazon-cloudwatch-agent (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Pufferüberlauf in corosync (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Ausführen beliebiger Kommandos in perl-DBI (SUSE)(29.09.2026 um 23:54 Uhr)
•
Unix & Linux ServerSecurity: Zwei Probleme in cjose (SUSE)(30.09.2026 um 00:10 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

while and do loop:

while loop Java while loop is a control flow statement used to execute the block of statements repeatedly until the given condition evaluates to false. Once the condition becomes false, the line immediately after the loop in the program…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

while loop



Java while loop is a control flow statement used to execute the block of statements repeatedly until the given condition evaluates to false. Once the condition becomes false, the line immediately after the loop in the program is executed.



The while loop loops through a block of code as long as a specified condition is true.



Syntax of while loop in Java:




while (test_expression) {   

// statements

update_expression;


}




Execution of While Loop in Java:



Image description



1.Control enters the while loop.

2.The condition is tested.

3.If true, execute the body of the loop.

4.If false, exit the loop.

5.After executing the body, update the loop variable.

6.Repeat from step-2 until the condition is false.



simple example:




public class Main {
public static void main(String[] args) {
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
}
}

output:
0
1
2
3
4







The Do-While Loop:



This do-while loop is an exit controlled loop that checks the condition at the end of the code. This loop ensures that the code is executed at least once.



Image description




**simple example:**

package B10;

public class loop {

public static void main(String[] args) {
int no=1;
do
{
System.out.println(no);
no=no+1;
}
while(no<=5);
}

}
output:
1
2
3
4
5









Differnce between while and do while loop:



Image description



Image description



Entry Control Loops



These control the entry to the loop. They check for a condition and the control is transferred inside the loop if, and only if, the condition is true. These loops are used when checking for a condition before execution is mandatory. Example include for and while loops.



Exit Control Loops



An exit control loop controls the exit. The exit control loop checks the condition for an exit. If the given condition for exit is true, control will exit from the loop body, or else control will enter again into the loop. Example is a do-while loop.



Increment and Decrement Operators:



Increment and Decrement Operators are Unary Operators commonly used in programming to increase or decrease the value of a variable by one, respectively.



Increment Operators:



Increment operators are used to increase the value of a variable by one. There are two types of increment operators:

The prefix increment operator (++x) and

The postfix increment operator (x++)



Prefix Increment Operator (++x):



The prefix increment operator increases the value of the variable by 1 before the value is used in the expression.

Syntax: ++x

Example: If x is initially 5, ++x will increment x to 6 and return the new value (6).



Postfix Increment Operator (x++):



The postfix increment operator increases the value of the variable by 1 after the value is used in the expression.

Syntax: x++

Example: If x is initially 5, x++ will return the current value of x (5) and then increment x to 6.




**Example program:**(Increment)

public class Main {
public static void main(String[] args)
{
int x = 5;
// Prefix increment: increment x by 1 and then print
// the value (6)
System.out.println(++x);
// Postfix increment: print the value of x (6) and
// then increment x by 1
System.out.println(x++);
// Output: 7
System.out.println(x);
}
}
output:
6
6
7






Decrement Operators:



Decrement operators are used in programming languages to decrease the value of a variable by one. Similar to increment operators, there are two types of decrement operators:

The prefix decrement operator (--x)

The postfix decrement operator(x--)



Prefix Decrement Operator (--x):

The prefix decrement operator decreases the value of the variable by 1 before the value is used in the expression.

Syntax: --x

Example: If x is initially 5, --x will decrement x to 4 and return the new value (4).



Postfix Decrement Operator (x--):



The postfix decrement operator decreases the value of the variable by 1 after the value is used in the expression.

Syntax: x--

Example: If x is initially 5, x-- will return the current value of x (5) and then decrement x to 4.




Example program:(Decrement)

public class Main {
public static void main(String[] args)
{
int x = 5;
// Prefix decrement: decrement x by 1 and then print
// the value (4)
System.out.println(--x);
// Postfix decrement: print the value of x (4) and
// then decrement x by 1
System.out.println(x--);
// Output: 3
System.out.println(x);
}
}
output:
4
4
3







References:

https://www.simplilearn.com/tutorials/javascript-tutorial/javascript-loops

https://www.geeksforgeeks.org/java-while-loop-with-examples/

https://www.w3schools.com/java/tryjava.asp?filename=demo_while_loop

https://studyopedia.com/java/loops-in-java/

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten while and do loop:

Thematisch verwandte Begriffe: while, loop · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY Kritische Sicherheitsmeldung
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag