Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Extended Version of for Loop in Java


Download 0.82 Mb.
Pdf ko'rish
bet28/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   24   25   26   27   28   29   30   31   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

Extended Version of for Loop in Java
As  of  Java  5,  the  upgraded  for  loop  was  presented.  This  is  basically  utilized  for  Arrays.
The syntax for this loop is as follows:
for(declaration : statement)
{
//Statements
}
Declaration:  The  recently  declared  variable,  which  is  of  a  sort  perfect  with  the
components of the show you are getting to. The variable will be accessible inside
the for piece and its esteem would be the same as the current array component.
Expression:  This  assesses  to  the  exhibit  you  have  to  loop  through.  The
interpretation can be an array variable or function call that returns an array.
Sample Implementation:
public class myTest {
public static void main(string args[]){


int [] mynumber = {0, 5, 10, 15, 20};
for(int i : mynumber ){
System.out.print( i );
System.out.print(” ,”);
}
}
This would deliver the accompanying result:
0, 5, 10, 15, 20

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   24   25   26   27   28   29   30   31   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling