0% found this document useful (0 votes)
82 views12 pages

Java Control Statements Explained

The document discusses various Java control statements including if-else, switch, while loops, do-while loops, for loops, break, continue, return, and labeled break and continue. It provides examples of how to use if/else, while loops, do-while loops, for loops, break, and continue. Labeled break and continue are used to break or continue from nested loops.

Uploaded by

Indrajeev Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views12 pages

Java Control Statements Explained

The document discusses various Java control statements including if-else, switch, while loops, do-while loops, for loops, break, continue, return, and labeled break and continue. It provides examples of how to use if/else, while loops, do-while loops, for loops, break, and continue. Labeled break and continue are used to break or continue from nested loops.

Uploaded by

Indrajeev Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Java Control Statements

[Link]

By Srinivas Reddy.S

Control Statements
if else switch while do while for break continue return Labeled break, continue

[Link]

if-else
if(conditional_statement){ statement to be executed if conditions becomes true }else{ statements to be executed if the above condition becomes false }
[Link]

switch
switch(byte/short/int){ case expression: statements case expression: statements default: statement }
[Link]

while - loop
while(condition_statementtrue){ Statements to be executed when the condition becomes true and execute them repeatedly until condition becomes false. } E.g. int x =2; while(x>5){ [Link](value of x:+x); x++; }
[Link]

do while - loop
do{ statements to be executed at least once without looking at the condition. The statements will be exeucted until the condition becomes true. }while(condition_statement);

[Link]

for - loop
for(initialization; condition; increment/decrement){ statements to be executed until the condition becomes false } E.g: for(int x=0; x<10;x++){ [Link](value of x:+x); }
[Link]

break
Break is used in the loops and when executed, the control of the execution will come out of the loop.
for(int i=0;i<50;i++){ if(i%13==0){ break; } [Link](Value of i:+i); }
[Link]

continue
Continue makes the loop to skip the current execution and continues with the next iteration. for(int i=0;i<50;i++){ if(i%13==0){ continue; } [Link](Value of i:+i); }
[Link]

return
return statement can be used to cause execution to branch back to the caller of the method.

[Link]

Labeled break,continue
Labeled break and continue statements will break or continue from the loop that is mentioned. Used in nested loops.

[Link]

[Link]

You might also like