# Print Ordered Numbers in Program

**URL:** <https://discourse.processing.org/t/print-ordered-numbers-in-program/19386>\
**Category:** Beginners\
**Created:** [April 4, 2020, 8:05am UTC](https://discourse.processing.org/t/print-ordered-numbers-in-program/19386 "2020-04-04T08:05:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TeaTea](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TeaTea](https://discourse.processing.org/u/TeaTea)\
**Post date:** [April 4, 2020, 8:05am UTC](https://discourse.processing.org/t/print-ordered-numbers-in-program/19386/1 "2020-04-04T08:05:37Z")

</div>

hello anyone who reads this 😄

i’m new to coding, i am trying to create things to practice coding, so i went to this page :

[http://www.beginwithjava.com/java/loops/questions.html](http://www.beginwithjava.com/java/loops/questions.html)

because i saw that in processing, it is using java to write codes, so i looked at this site’s practice exercise to try to practice coding.

the first question is to print number from 1-10, i tried and failed, so i watched the solution, and pasted it in processing to see if it works, but it didn’t work - i don’t know what’s the problem…

so then i changed the codes according to my limited “knowledge” (barely can amount to claim this word) , and still doesn’t work…

i want to get through the question, but i am stuck at the first one…

i wonder if anyone can help me with solving this puzzle??

thank you in advance ^^

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 4, 2020, 10:32am UTC](https://discourse.processing.org/t/print-ordered-numbers-in-program/19386/2 "2020-04-04T10:32:43Z")

</div>

Hello,

There are some on-line java compilers.  
This came up first in search:  
[https://www.tutorialspoint.com/compile\_java\_online.php](https://www.tutorialspoint.com/compile_java_online.php)

This is what Processing is (Wikipedia definition):

> **[Processing](https://en.wikipedia.org/wiki/Processing_(programming_language))**
>
> Processing is a free graphics library and integrated development environment (IDE) built for the electronic arts, new media art, and visual design communities with the purpose of teaching non-programmers the fundamentals of computer programming in a visual context.
> Processing uses the Java language, with additional simplifications such as additional classes and aliased mathematical functions and operations. It also provides a graphical user interface for simplifying the compilation and execution...

I would start here to understand the Processing environment:

> **[Welcome to Processing!](https://processing.org)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

Be sure to check out the tutorials.

And here:

> **[The Coding Train](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)**
>
> All aboard! The Coding Train is on its way with creative coding video tutorials on subjects ranging from the basics of programming languages like JavaScript to algorithmic art, machine learning, simulation, generative poetry, and more. Choo choo!

You can print() to the console and write text() to the canvas; look in the Processing reference for these.

There are also many examples that come with the Processing PDE (IDE):

These are in File \> Examples…  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5ae14cc3ec6f68a9ea50907ae7453870c9e7133f.png)

`:)`

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 4, 2020, 12:27pm UTC](https://discourse.processing.org/t/print-ordered-numbers-in-program/19386/3 "2020-04-04T12:27:18Z")

</div>

> [@TeaTea](#):
>
> … because I saw that in Processing, it is using Java to write codes,

Indeed Processing sketches become Java code just before they’re compiled when we hit the “Run” button (CTRL + R).

But notice that the default extension in Processing is “.pde” and not “.java”.

It means that its syntax is slightly diff. than Java’s, and it still needs some small behind-the-scenes changes in order to output a 100% fully compliant Java compilable code.

All the “.pde” files within a Processing’s IDE (PDE) project folder are concatenated as 1 file.

Then the PDE’s preprocessor transpiles that 1 single “.pde” to a “.java” file, wrapping up our whole code as 1 [`class`](https://processing.org/reference/class.html) that [`extends`](https://processing.org/reference/extends.html) PApplet:  
[Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html)

> [@TeaTea](#):
>
> The first question is to print numbers from 1 to 10; I tried and failed,

This is your site link’s Java syntax answer for it:

```auto
public class PrintNumbers
{
    public static void main(String[] args)
    {
        for(int i=1; i<=10; i++)
        {
            System.out.println(i);
        }
    }
}

```

In order to convert that Java syntax code to Processing’s we need to pay attention to some details of it.

The code we actually want is just this: `for (int i = 1; i <= 10; i++) System.out.println(i);`

That code is inside a method called **main()**, which in turn is wrapped up inside a `class` called PrintNumbers.

The method **main()** is special to Java b/c it acts as the entry-point where the code starts.

However, Processing’s preprocessor creates its own custom **main()** behind-the-scenes.

Therefore it’s highly unrecommended to attempt creating our own **main()**!

As I’ve mentioned before, all “.pde” files end up wrapped up as 1 PApplet subclass; so we don’t need PrintNumbers either!

Another cool thing is that Processing’s already got a function called **println()**:

> **[println() / Reference](https://processing.org/reference/println_.html)**
>
> The println() function writes to the console area, the black rectangle at the bottom of the Processing environment. This function is often helpful for looking at the data a program is producing…

Even though **System.out.println()** still works in Processing, there’s no point to type in such boilerplate when we can go w/ just **println()**!

Now, after removing the `class` PrintNumbers and its **main()** method, all that’s left is:

```auto
for (int i = 1; i <= 10; ++i) println(i);

```

Just copy & paste that 1-liner in Processing and it will just magically run!

That’s called immediate mode, when we don’t create any functions in our “.pde” tab file.

However, most of the time we’re gonna need to create our callback **setup()**, which in some way acts like Java’s **main()**:

> **[setup() / Reference](https://processing.org/reference/setup_.html)**
>
> The setup() function is run once, when the program starts. It's used to define initial environment properties such as screen size and to load media such as images and fonts as the program start…

```auto
void setup() {
  for (int i = 1; i <= 10; println(i++));
  exit();
}

```

When we define Processing callbacks, it’s called interactive mode.

---

<div class="post-metadata">

**Author:** ![TeaTea](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TeaTea](https://discourse.processing.org/u/TeaTea)\
**Post date:** [April 5, 2020, 10:06am UTC](https://discourse.processing.org/t/print-ordered-numbers-in-program/19386/4 "2020-04-05T10:06:09Z")

</div>

thank you sooooo much!!! i have been reading and trying some more basic things according to those reference^^

i wanted to reply as soon as i saw the replies, but i’ve decided to only reply when i figured it out!!!

and i haven’t figured anything out! because it is you guys who figured it out for me lol

i read the help from GoTooLoop, taught me a great deal about processing…!!! thank you GoToLoop… thank you thank you!!!

i tried running the codes for about 100 times, restarted the program… wondering what’s wrong lol , then i realised… my problem was that i thought it would show up in the box that pops up after i clicked “Run” - truth is it’s gonna show up in the Console area lololol the answer was there but i just couldn’t see it because i had my eyes hoping it’d show up in that pop-up box…

i’m so delighted now lol i hope this is of use to somebody else that’s in the same place that i was lol

thank you so much, glv and GoToLoop…!!! if not for your replies, i don’t know how long would i have lasted at that square, which actually lasted for about 2 weeks…

now i’ll go conquer the next questions in that site!!! ^^ too delighted…!!!

thank youuuuuu : ) : ) : )
