help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] scripting error ?


From: Mehul N. Sanghvi
Subject: [Help-smalltalk] scripting error ?
Date: Tue, 09 Dec 2008 10:26:28 -0500
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

OK so I've started scripting and can do the simple

   'Hello' printNl . !

type of script.

I have the following:

    #! /bin/sh
    "exec" "gst" "-f" "$0" "$@"

    'Project Euler:  Problem 1: ' print .

    | sum i limit |
    sum := 0 .
    i := 0 .
    limit := 10 .

    [ i := i + 1.
i < limit ifTrue: [ ((( i \\ 3) = 0) | ((i \\ 5) = 0)) ifTrue: [ sum := sum + i ] ].
    ] repeat.

    !


This will do the print, and then just wait there. All I want to do is a simple while-loop type thing where the code loops until counter reaches 1000. Here's the equivalent Perl code:


#!/usr/bin/env perl

use integer;

print("\nProblem 1: \n");

$i = 0;
$limit = 1000;
$total_sum = 0;

while ( $i < $limit )
  {
    if ( $i % 3 == 0 )
      {
        $total_sum += $i ;
      }
    elsif ( $i % 5 == 0 )
      {
        $total_sum += $i ;
      }

    $i++ ;
  }

print ("Answer 1: $total_sum\n");




Any suggestions for what I'm doing wrong ? I'm new to Smalltalk as you can probably guess by my Smalltalk.


cheers,

    mehul





reply via email to

[Prev in Thread] Current Thread [Next in Thread]