Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7649275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:55:28+00:00 2026-05-31T10:55:28+00:00

So basically this code’s purpose is to simply print out the first n even

  • 0

So basically this code’s purpose is to simply print out the first n even numbers.

for (i = 0; i <=n; i+= 2)
{
    print i;
}

Thing is though, I don’t understand Scheme at all. So, help please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:55:30+00:00Added an answer on May 31, 2026 at 10:55 am

    There are several ways to convert the code in the question to Scheme. The first one I can think of:

    (define (print-even n)
      (let loop ((i 0))
        (if (<= i n)
            (begin
              (print i)
              (newline)
              (loop (+ i 2))))))
    

    Notice this:

    • The solution is written as a recursive procedure
    • Instead of a for loop, I’m using a construct called a named let, which permits the initialization of some iteration variables (i in this case, initialized to 0) and the repeated execution of a recursive procedure (loop in this case), producing an effect similar to a for, even in performance
    • The stop condition in the “loop” is handled with essentially the same expression: repeat the body of the iteration as long as (<= i n), when that condition becomes false, the iteration ends
    • The begin surrounds the body of the “loop”, just as the curly braces {} do in the original code
    • The print procedure performs the expected operation; for readability I added a new line after printing each number
    • The increment part of the original loop i += 2 is handled by the expression (+ i 2), inside the recursive call

    So you see, the process being executed is essentially the same, only the way to write it (the syntax!) is different. Give it a try, type this:

    (print-even 6)
    

    … And the following will get printed on the screen:

    0
    2
    4
    6
    

    Another possible way to implement the procedure, more similar to the original code, although (this is completely subjective) less idiomatic than the previous one:

    (define (print-even n)
      (do ((i 0 (+ i 2))) ((> i n))
        (print i)
        (newline)))
    

    Finally, if you’re using Racket this will seem even more familiar to you:

    #lang racket
    
    (define (print-even n)
      (for ((i (in-range 0 (+ n 1) 2)))
        (print i)
        (newline)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically this code below returns the right information, but I need to add the
So basically this code was working fine before. I had some computer issues and
This code basically translates characters based on position in one string to the character
I am using this code to alter the title of an image. Basically it
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
Basically i am having problems with my code - this is homework so would
I recently came across this in some code - basically someone trying to create
So I was writing some code today that basically looks like this: string returnString
I'm trying to modify the code from this script . Basically I'm trying to
This isn't a code question for once, but it definitely has me confused. Basically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.