Osnove pythona

if-stavek

Primer:
a = [1,2,3,4,5,6,7]
if len(a) < 2:
  print "kratek."
elif len(a) < 5:
  print "srednji."
else:
  print "kao dolg."
    

For zanka

for i in range(5):
  print i
    
sprinta 0\n1\n2\n3\n4\n

Tabele

a = ['a',1,5]
print a[0] # sprinta a
print a[1] # sprinta b
print a[3] # sprinta c
# ekvivalentno
for element in a:
  print element
    

Osnove php-ja

if-stavek

Primer:
$a = array(1,2,3,4,5,6,7);
if (count($a) < 2) {
  echo "kratek.";
} else if (count($a) < 5) {
  echo "srednji.";
} else {
  echo "kao dolg.";
}
    

For zanka

for ($i=0; $i < 5; ++$i) {
  echo $i, "\n";
}
    
sprinta 0\n1\n2\n3\n4\n

Tabele

$a = array('a',1,5);
echo $a[0]; # a
echo $a[1]; # b
echo $a[3]; # c
# ekvivalentno
foreach ($a as $element) {
  echo $element;
}
    

Osnove c-ja

if-stavek

Primer:
int a[] = {1,2,3,4,5,6,7};
int len = sizeof(a);
if (len < 2) {
  printf( "kratek." );
} else if (len < 5) {
  printf( "srednji." );
} else {
  printf( "kao dolg." );
}
    

For zanka

for (int i=0; i < 5; ++i) {
  printf( "%d\n", i);
}
    
sprinta 0\n1\n2\n3\n4\n

Tabele

int a[3] = {0,1,5};
printf( "%d\n", a[0] ); //0
printf( "%d\n", a[1] ); //1
printf( "%d\n", a[2] ); //5
# ekvivalentno
for (int i=0; i < 5; ++i) {
  printf( "%d\n", a[i]);
}