Källkod

Välj en PHP-fil för att visa dess källkod.

exercises/ovn_gr3.php

<?php
require __DIR__ . '/../incl/config.php';
$sum_for = 0;
for (
$i = 1; $i <= 100; $i++) {
    
$sum_for += $i;
}

$sum_while = 0;
$j = 1;
while (
$j <= 100) {
    
$sum_while += $j;
    
$j++;
}

$baseUrl = '../';
$title = 'Uppgift 3 - Grunder';
require 
__DIR__ . '/../incl/header.php';
?>

    <h1>Summan av de 100 första heltalen</h1>
    <p>Summan beräknad med for-loop: <strong><?php echo $sum_for; ?></strong></p>
    <p>Summan beräknad med while-loop: <strong><?php echo $sum_while; ?></strong></p>

<?php require __DIR__ . '/../incl/footer.php'; ?>