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


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

The do…while Loop
A  do…while  loop  is  similar  to  the  while  looping  construct  aside  from  that  a  do…while
circle is ensured to execute no less than one time. The syntax for this looping construct is
as follows:
do {
/Statements
}while();
Perceive that the Boolean declaration shows up toward the end of the circle, so the code
execute  once  before  the  Boolean  is  tried.  In  the  event  that  the  Boolean  declaration  is
genuine, the stream of control bounced go down to do, and the code execute once more.
This methodology rehashes until the Boolean articulation is false.
Sample implementation:
public class myTest {
public static void main(string args[]){
int i = 1;
do{
System.out.print(“i = ” + i );
i++; System.out.print(“\n”);


}while( i<1 );
}
This would create the accompanying result:
i = 1
The for Loop
A for circle is a reiteration control structure that permits you to effectively compose a loop
that needs to execute a particular number of times. A for looping construct is helpful when
you know how often an errand is to be rehashed. The syntax for the looping construct is as
follows:
The punctuation of a for circle is:
for(initialization; Boolean_expression; redesign)
{
/Statements
}
Here is the stream of control in a for circle:
The introduction step is executed in the first place, and just once. This step permits
you to pronounce and introduce any loop control variables. You are not needed to
put an announcement here, the length of a semicolon shows up.
Next,  the  Boolean  outflow  is  assessed.  In  the  event  that  it  is  genuine,  the
assemblage of the loop is executed. In the event that it is false, the assortment of
the loop does not execute and stream of control hops to the following articulation
past the for circle.
After the group of the for circle executes, the stream of control bounced down to
the  overhaul  explanation.  This  announcement  permits  you  to  overhaul  any  circle
control  variables.  This  announcement  can  be  left  clear,  the  length  of  a  semicolon
shows up after the Boolean declaration.
The Boolean outflow is currently assessed once more. On the off chance that it is
genuine,  the  loop  executes  and  the  scope  rehashes  itself.  After  the  Boolean
declaration is false, the for loop ends.
Sample Implementation


public class myTest {
public static void main(string args[]) {
for(int i = 0; i < 5; i = i+1) {
System.out.print(“i = ” + i );
System.out.print(“\n”);
}
}
This would deliver the accompanying result:
i = 0
i = 1
i = 2
i = 3
i = 4

Download 0.82 Mb.

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




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