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 9129089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:40:00+00:00 2026-06-17T07:40:00+00:00

I am a complete beginner and I’m trying to follow the logic behind this

  • 0

I am a complete beginner and I’m trying to follow the logic behind this code snippet.

int x = 12;
do {
    for (int w=9; w<x; w++)
        System.out.print(w+” ”);
    --x;
    System.out.println(x);
}while (x>7);

When I run it, the answer is as follows:

9 10 11 11
9 10 10
9 9
8
7

If someone could explain how to read the code step by step in a simple way I would be very happy!

  • 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-06-17T07:40:01+00:00Added an answer on June 17, 2026 at 7:40 am

    int x = 12; declare new local variable, called x

    do { begins new do...while loop

    for (int w=9; w<x; w++) begins new for loop which will iterate until value of variable w is less then value of variable x. After each iteration of this loop variable w will increase its value (by w++). Initial value of variable w is 9 (int w=9).

    System.out.print(w+” ”); this one prints out to console current value of variable w plus one white-space after that

    --x; this one decreases value of x variable. It is such called prefix version of operation --

    System.out.println(x); prints value of x variable to console and returns carriage

    } end of for loop code block (fixed thanks to Chris)

    } while (x>7); end of while code block with condition on which loop will end: until value of variable x is more then 7 loop will run.

    UPD: More specifically explaining output result:

    1) 1-st iteration of do loop. We have x == 12:

    iterations of internal for loop:

    1.1) w == 9 , 9 < 12 => outputs 9 to console

    1.2) w++ => w == 10, 10 < 12 => outputs 10 to console,

    1.3) w++ => w == 11, 11 < 12 => outputs 11 to console,

    1.4) w++ => w == 12, 12 == 12 => ends for loop

    2) for loop ends. --x => x == 11 , outputs 11 to console and returns carriage, so we have line 9 10 11 11

    3) begins new iteration of do ... while loop with x == 11 and so on until x became equals to 7.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a complete beginner to this language and am currently trying to create a
Note: Near complete beginner to logic programming I need to compare two lists of
I am beginner trying to complete a simple JSON problem on SingPath which asks
I am a complete beginner to website design and I am trying to create
I am a complete beginner here. Can someone please post some Delphi code to
I'm a (near complete) beginner, and this is my first foray into encryption -
I'm a complete beginner, and this is how I understand linking: Static linking copies
I'm still a complete beginner in the field of web development and I'm trying
I am a complete beginner in asp.net, C#, etc... I saw this and this
I'm a complete beginner to Excel VBA. The following is code I've written that

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.