menu
Menu
Drakon.Tech logo
Drakon.Tech
Get started
Drakon.Tech documentationProgramming in DRAKONThe basics of programming with Drakon.TechHello worldVariables and functionsif-else | Question iconswitch-case | the Choice iconThe foreach loopThe arrow (while) loopSilhouetteClassesLambdas and exceptionsAdvanced programming methodsGame examplesThe source codeLegacy tutorials (JavaScript 0.2)

if-else | Question icon

Ru | En

Source code: Question

The DRAKON equivalent of the if-else statement is the Question icon.

Let's design a function called printNumber. That function will take a number and output the text representation of the number. We start using printNumber as if it existed.

Calling functions in Drakon.Tech

Now, let's create the printNumber function. It will accept one argument called number.

We add a Question icon. If number is equal to 10, we print "ten." We also output number itself for reference. Let's build the module and run the app.

The Question icon

We open the console and see online one line.

10 "ten"

Our printNumber function can handle only value 10. Let's add support for all other values. If number is not equal to 10, we print "some other value."

The Question icon

We build and run again. Now, there are three lines in the output.

10 "ten"
20 "some other value"
30 "some other value"

Question icons can form complex decision trees. We will add another Question icon. If number is equal to 20, we print "twenty."

A more complex decision tree with the Question icon

We should get a greater variety of results now. We build, reload, and check the console.

10 "ten"
20 "twenty"
30 "some other value"

Note that it is possible to swap the "Yes" and "No" labels on a Question icon. Right-click it and choose "Swap Yes and No." To preserve the logic of the algorithm, we must rearrange the paths on the flowchart.

I extensively use Copy, Cut, and Paste operations to achieve this. Here, I also have to rewire some of the lines.

First, I click on a line (or its end). Then, I choose the new path by clicking on a yellow circle.

A more complex decision tree with the Question icon

Let's build the module and run the app after this re-arrangement. As we expect, the core of the algorithm remained the same.

10 "ten"
20 "twenty"
30 "some other value"
Source code: Question
close
Close
Drakon.Tech logo
Drakon.Tech home
Programming in DRAKONThe basics of programming with Drakon.TechAdvanced programming methodsThe source codeLegacy tutorials (JavaScript 0.2)