What's new

Closed Paano po yung concept ng pyramid?

Status
Not open for further replies.
Bawat next line madadagdagan po yung bilang ng i-output na ASCII character(ikaw na po bahala kung anong character yung gagamitin) at magstostop yung loop kung hindi na nasa-satisfy yung sinet na condition.
 
Basic, hmm....

Ganito ang components ng loop:
  • Initialization - maga-assign ka ng initial value sa isang variable.
  • Condition - as long as na-sasatisfy yung condition, patuloy ang process na nakapaloob sa looping statement.
  • Iteration - kung anong mangyayari dun sa variable na kinocompare; pwede mag-increment(++) o pwede ring mag-decrement(--).
 
looping eto po yung paulit ulit na execution ng statement or group of statements habang yung condition ay true.
Magagawa mo ito sa pamamagitan ng for loop, while loop at do...while loop.

for loop:
for(initialization; condition ; increment/decrement)
{
statement(s);
}

Ex.
class ForLoopExample {
public static void main(String args[]){
for(int i=10; i>1; i--){
//eto ung statement na inuulit habang //ung i>1(ung condition mo)
System.out.println("The value of i is: "+i);
}
}
}

while loop:
while(condition)
{
statement(s);
}

Ex.
class WhileLoopExample {
public static void main(String args[]){
int i=10;
while(i>1){
System.out.println(i);
//i dedecrement mo ung i pra mabago //ung condition at patuloy ang pag //loop netong statement
i--;
}
}
}

do...while loop:
Pareho lang ng while loop kaso unang maeexexute ung statement(s) bago i check ung condition.

do{
statement(s);
}while(condition);

Ex.
public class DoWhileLoopExample{
public static void main(String args[]) {
int x = 10;
do {
System.out.print("value of x : " + x );
x++;
}while( x < 20 );
}
}
 
Status
Not open for further replies.
Back
Top