Pertemuan V

1. While

#include <iostream.h>
#include <stdio.h>
#include <conio.h>

main()
{
    int n=1;

	while(n<=5){
   	cout<<n<<endl;
      n++; 

   }

	getch();
}

while php

<?php

$n=1;
while($n<=5)
{
	echo $n."<br>";
	$n++;	
}

?>

While —

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
 
main()
{
    int n=10;
 
    while(n>0){
    cout<<n<<endl;
      n--;

   }
 
    getch();
}

while php

<?php

$n=10;
while($n>0)
{
	echo $n."<br>";
	$n--;	
}

?>

2. do while

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
 
main()
{
    int n=0;
 
	do{
    cout<<n<<endl;
      n+=2;

   }
       while(n<=10);

    getch();
}

do while php

<?php

$n=2;
do
{
	echo $n."<br>";
	$n+=2;	
}
while($n<=10);

?>

do while c++

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>

main()
{
    int n=0;
    char a[]="ubsi PSDKU Purwokerto";

	do{
    cout<<a<<endl;
      n++;

   }
       while(n<=10);

    getch();
}       

do while php

<?php

$n=0;
$a="ubsi PSDKU Purwokerto";
do
{
	echo $a."<br>";
	$n++;	
}
while($n<=10);

?>

3. For

For Negatif [Menurun] c++

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
 
main()
{
    int n;
 
    for(n=10;n>0;n--)
    {
    	cout<<n<<endl;
    }
 
    getch();
}

for negatif php

<?php
for($n=10;$n>0;$n--)
{
	echo $n."<br>";	
}
?>

for positif c++

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
 
main()
{
    int n;
 
    for(n=1;n<=10;n++)
    {
    	cout<<n<<endl;
    }
 
    getch();
}

for positif php

<?php
for($n=1;$n<=10;$n++)
{
	echo $n."<br>";	
}
?>

Nested For C++

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
main()
{ int i, j;
for (i=1; i<=10; i++)
{ cout<<endl;
for (j=1; j<=i; j++)
cout<<"*";}
getch();
}

Nested For php

<?php

for($i=1;$i<=10;$i++){
	
	for($j=1;$j<=$i;$j++)
	{
		echo "*";
	}
	
	echo "<br>";
	
}
?>

Tags:,

Leave a Reply