vi studio

Lessons · The language · 16 of 36

Programs without a screen

main functions and print().

Mark a function main instead of a container, and Vi runs it once as a console program: no screen, just what it prints. Studio shows a Console screen with the output and a Run again button.

main times_table():
  for n in [1, 2, 3, 4, 5]:
    print(n, "× 7 =", n * 7)

A file can have both a main container and a main function: the app shows the screen and runs the function once when it starts.

Every example here runs in Vi Studio: open it in your browser (phones too) and press Start learning on the welcome page. Each code block there has a Try it button that runs it in the phone preview.

More in The language

About Vi. Vi is a free, open-source programming language for building real mobile apps. You describe each screen in plain words, and Vi compiles it to React Native (Expo) for Android, iOS and the web. Its editor, Vi Studio, runs on Windows, in any browser and on your phone, with the app running live as you type. Read more about Vi.