View Single Post
  #4   Spotlight this post!  
Unread 08-09-2005, 15:23
sciguy125 sciguy125 is offline
Electrical Engineer
AKA: Phil Baltar
FRC #1351
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Sunnyvale, CA
Posts: 519
sciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond reputesciguy125 has a reputation beyond repute
Send a message via AIM to sciguy125 Send a message via MSN to sciguy125 Send a message via Yahoo to sciguy125
Re: Karel++ Noob help

Ok, I just took a crash course in Karel++. That was the fastest I've ever learned a new language. For those of you who are wondering, it turns out that Karel++ is the language you would get if LOGO and C++ had a child that was raised by BASIC (not sure how that works, but that's what it looks like to me).

Karel++ doesn't have a "for" loop, but it does have "loop" loop.

Code:
loop(5)
{
  move(); //calls move() 5 times
}
I'm not sure if it supports non-void functions (or "instructions" as they seem to be called). All the examples I found don't take or return parameters in the functions. Because of the way the language is designed, I suspect that the following code might work, but I don't have Karel++, so I can't test it.

Code:
void movenum(n)
{
  loop(n)
  {
    move();
  }
}
Just as some general advice: Whenever possible, it's a good idea to make multipurpose code. Your example of using 15 separate functions works, but it's not very clean. If you wanted to expand it for some reason, you might have a hard time doing so because it only does one thing. It also makes it hard to read any code that uses those functions.
__________________

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GE/S/P a-- e y-- r-- s:++ d+ h! X+++
t++ C+ P+ L++ E W++ w M-- V? PS+ PE+
5- R-- tv+ b+ DI+++ D- G
------END GEEK CODE BLOCK------